camera-live-streaming
camera-live-streaming copied to clipboard
feat: Set up complete Python testing infrastructure with Poetry
Set up Complete Python Testing Infrastructure with Poetry
Summary
This PR establishes a comprehensive testing infrastructure for the Python project, migrating from a basic requirements.txt setup to a modern Poetry-managed environment with robust testing capabilities.
Changes Made
Package Management
- Migrated to Poetry: Created
pyproject.tomlwith Poetry configuration - Dependency Migration: Moved dependencies from
requirements.txtto Poetry format - Updated OpenCV: Upgraded opencv-python to ^4.8.0 for better compatibility
Testing Dependencies Added
pytest ^7.0.0- Main testing frameworkpytest-cov ^4.0.0- Coverage reportingpytest-mock ^3.10.0- Mocking utilities
Testing Configuration
- pytest Configuration: Comprehensive setup in
pyproject.tomlwith:- 80% coverage threshold requirement
- HTML and XML coverage report generation
- Custom markers:
unit,integration,slow - Strict configuration and output formatting
- Coverage Configuration: Detailed coverage settings with source inclusion/exclusion rules
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_setup_validation.py # Infrastructure validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Testing Fixtures
Created comprehensive fixtures in tests/conftest.py:
temp_dir,temp_file- Temporary filesystem resourcessample_data- Common test data structuresmock_config,mock_database,mock_logger- Mock objectsjson_file,text_file- Temporary files with contentmock_environment- Environment variable setupcapture_logs- Log capture utilities
Development Workflow
- Poetry Scripts: Added
poetry run testandpoetry run testscommands - Coverage Reports: Generates
htmlcov/directory andcoverage.xmlfile - Git Integration: Updated
.gitignorewith testing artifacts and development files
Validation
- 21 Validation Tests: Comprehensive test suite verifying:
- Infrastructure setup and configuration
- All fixtures functionality
- Project structure integrity
- Pytest markers and parametrization
- All Tests Passing: Infrastructure validated and ready for development
Instructions for Running Tests
Installation
poetry install
Running Tests
# Both commands work identically
poetry run test
poetry run tests
# Direct pytest with all configured options
poetry run pytest
Coverage Reports
- Terminal: Coverage summary displayed after test run
- HTML Report: Open
htmlcov/index.htmlin browser - XML Report:
coverage.xmlfor CI/CD integration
Using Custom Markers
poetry run pytest -m unit # Run only unit tests
poetry run pytest -m integration # Run only integration tests
poetry run pytest -m "not slow" # Skip slow tests
Notes
- Coverage Threshold: Set to 80% - currently failing as expected since no application tests exist yet
- Poetry Lock:
poetry.lockfile created and should be committed for dependency locking - Ready for Development: Infrastructure is fully functional and ready for writing actual application tests
- Fixtures Available: Comprehensive set of reusable fixtures for common testing scenarios
Next Steps
Developers can now immediately start writing tests by:
- Creating test files in
tests/unit/ortests/integration/ - Using the provided fixtures from
conftest.py - Running tests with
poetry run test - Viewing coverage reports in
htmlcov/
🧪 Testing infrastructure is now complete and validated!