XBlock-ETH
XBlock-ETH copied to clipboard
feat: Set up comprehensive Python testing infrastructure
Set up Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the XBlock-ETH project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Added Poetry configuration in
pyproject.tomlwith project metadata and dependencies - Migrated dependencies from existing codebase (primarily
requestsfor data downloading) - Set up development dependencies:
pytest,pytest-cov,pytest-mock
Testing Configuration
- Pytest configuration with test discovery patterns, coverage settings (75% threshold), and custom markers (
unit,integration,slow) - Coverage reporting in HTML, XML, and terminal formats with branch coverage enabled
- Test filtering and strict configuration for reliable test execution
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and test configuration
├── test_setup_validation.py # Infrastructure validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Testing Fixtures
The conftest.py provides comprehensive fixtures for:
- Temporary directories for test file operations
- Mock objects for zipfiles, HTTP requests, and file operations
- Sample data for blocks and transactions
- Network isolation to prevent actual HTTP calls during testing
- Environment cleanup for consistent test runs
Updated Configuration
- Enhanced
.gitignorewith testing artifacts, Python cache files, virtual environments, and IDE files - Validation tests to verify all components work correctly together
How to Run Tests
Install Dependencies
poetry install
Run All Tests
poetry run pytest
Run with Verbose Output
poetry run pytest -v
Run Specific Test Types
poetry run pytest -m unit # Unit tests only
poetry run pytest -m integration # Integration tests only
poetry run pytest -m slow # Slow tests only
Generate Coverage Report
poetry run pytest --cov-report=html
# Open htmlcov/index.html in browser
Validation
The infrastructure has been validated with 18 passing tests that verify:
- ✅ Python version compatibility (3.8+)
- ✅ All testing dependencies import correctly
- ✅ Custom test markers function properly
- ✅ Project structure is correct
- ✅ Shared fixtures work as expected
- ✅ Test discovery and execution work properly
- ✅ Coverage reporting generates successfully (77.90% coverage achieved)
Notes
- Poetry lock file is included in version control for reproducible builds
- Coverage threshold set to 75% for initial setup, can be increased as test suite grows
- Network calls blocked by default in tests to ensure fast, reliable execution
- Flexible fixture system allows easy extension for project-specific testing needs
The testing infrastructure is now ready for developers to start writing unit and integration tests for the blockchain data analysis functionality.