LightCNN
LightCNN copied to clipboard
feat: set up Python testing infrastructure with Poetry and pytest
Set Up Python Testing Infrastructure
Summary
This PR establishes a complete testing infrastructure for the LightCNN Python project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry configured as the package manager (default choice, no existing package manager found)
- Added
pyproject.tomlwith proper Poetry configuration - Set package-mode to false since this is a script-based project
Testing Dependencies
Added as development dependencies:
pytest(^7.4.0) - Core testing frameworkpytest-cov(^4.1.0) - Coverage reportingpytest-mock(^3.11.1) - Mocking utilities
Testing Configuration
Configured in pyproject.toml:
- pytest settings:
- Test discovery patterns for
test_*.pyand*_test.py - Custom markers:
unit,integration,slow - Strict marker enforcement
- Verbose output
- Test discovery patterns for
- Coverage settings:
- 80% coverage threshold target
- HTML and XML report generation
- Excluded directories: tests, virtual environments, build artifacts
- Coverage lines exclusion patterns
Directory Structure
Created proper testing structure:
tests/
├── __init__.py
├── conftest.py # Shared pytest fixtures
├── test_setup_validation.py # Infrastructure validation
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Fixtures (conftest.py)
Comprehensive set of reusable fixtures:
temp_dir- Temporary directory managementmock_config- Mock configuration objectssample_data- Test data samplesmock_model- Mock ML modeltest_image_path- Temporary test image filestest_data_file- Temporary data filesreset_modules- Module isolation between testscapture_logs- Log capture utilitymock_torch- PyTorch mocking for tests
Additional Setup
- Updated
.gitignorewith:- Testing artifacts (.pytest_cache/, coverage files)
- Poetry lock file preservation
- Claude settings (.claude/*)
- IDE and build artifacts
How to Use
Install Dependencies
# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -
# Install project dependencies
poetry install
Run Tests
# Run all tests
poetry run pytest
# Run with coverage
poetry run pytest --cov=. --cov-report=html
# Run specific test markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"
Writing Tests
- Place unit tests in
tests/unit/ - Place integration tests in
tests/integration/ - Use fixtures from
conftest.pyfor common test needs - Mark tests appropriately with
@pytest.mark.unit,@pytest.mark.integration, or@pytest.mark.slow
Validation
The setup includes validation tests in test_setup_validation.py that verify:
- pytest is properly installed
- Project structure is correct
- All fixtures work as expected
- Test markers function properly
- Test discovery is configured correctly
All validation tests pass successfully ✅
Notes
- Coverage reporting is configured but the threshold check is currently disabled for infrastructure-only setup
- The project uses Poetry in non-package mode since it appears to be a script-based project
- Python 3.8+ is required as specified in dependencies