Skip to content

feat: Set up comprehensive Python testing infrastructure#16

Open
llbbl wants to merge 1 commit intotczpl:mainfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up comprehensive Python testing infrastructure#16
llbbl wants to merge 1 commit intotczpl:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 3, 2025

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.toml with project metadata and dependencies
  • Migrated dependencies from existing codebase (primarily requests for 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 .gitignore with 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.

- Add Poetry package management with pyproject.toml configuration
- Install pytest, pytest-cov, and pytest-mock as development dependencies
- Configure comprehensive testing settings with 75% coverage threshold
- Create tests/ directory structure with unit/ and integration/ subdirectories
- Add shared fixtures in conftest.py for temp directories, mock data, and network isolation
- Include validation tests to verify testing infrastructure functionality
- Update .gitignore with testing artifacts, Python cache files, and development environment entries
- Support both `poetry run pytest` command execution for running tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant