feat: Set up complete Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR sets up a complete testing infrastructure for the Python project using Poetry as the package manager and pytest as the testing framework. The setup provides a ready-to-use testing environment where developers can immediately start writing tests.
Changes Made
Package Management
- Poetry Setup: Configured Poetry as the package manager via
pyproject.toml - Dependency Migration: Migrated existing dependencies from
requirements.txtto Poetry - Lock File: Poetry will generate a
poetry.lockfile for reproducible builds
Testing Framework
- pytest: Configured as the main testing framework (v8.0.0+)
- pytest-cov: Added for coverage reporting (v5.0.0+)
- pytest-mock: Included for mocking utilities (v3.14.0+)
Configuration
- Test Discovery: Configured to find tests matching
test_*.pyor*_test.pypatterns - Coverage Settings:
- Reports in HTML, XML, and terminal formats
- Covers
configs,tools, andutilsmodules - Excludes
netsandprojectsdue to external dependencies
- Custom Markers: Added
unit,integration, andslowmarkers for test categorization
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared pytest fixtures
├── test_setup_validation.py # Validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Fixtures Available
The conftest.py file provides these reusable fixtures:
temp_dir: Temporary directory for test filesmock_config: Mock configuration dictionarysample_yaml_config: Creates a sample YAML config filemock_image_path: Mock image file pathmock_checkpoint_path: Mock checkpoint file pathsample_project_structure: Creates project directory structurereset_modules: Auto-resets module imports between testscapture_logs: Captures loguru logs for testingmock_training_data: Provides mock training data
How to Use
Installation
# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -
# Install project dependencies
poetry install
Running Tests
# Run all tests
poetry run test
# or
poetry run tests
# Run with specific markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"
# Run specific test files
poetry run pytest tests/test_setup_validation.py
# Run with custom pytest options
poetry run pytest -v --tb=short
Coverage Reports
After running tests, coverage reports are available in:
- Terminal: Displayed automatically after test run
- HTML:
htmlcov/index.html(open in browser) - XML:
coverage.xml(for CI/CD integration)
Notes
-
Dependencies: The project has some modules (
nets) that require PyTorch, which isn't included in the base dependencies. These are excluded from coverage reporting. -
Python Version: Requires Python 3.8 or higher
-
Poetry Lock File: The
poetry.lockfile should be committed to ensure consistent dependency versions across environments -
Test Organization: Tests should be organized into
unit/andintegration/subdirectories based on their scope
Next Steps
Developers can now:
- Write unit tests in
tests/unit/ - Write integration tests in
tests/integration/ - Use the provided fixtures for common testing needs
- Run tests with coverage to ensure code quality