achoz
achoz copied to clipboard
feat: Set up comprehensive Python testing infrastructure
Set up comprehensive Python testing infrastructure
Summary
This PR establishes a complete testing infrastructure for the achoz project, migrating from the old setup.py based configuration to a modern Poetry-based development environment with comprehensive testing capabilities.
Changes Made
Package Management Migration
- Migrated from setup.py to Poetry: Created comprehensive
pyproject.tomlwith all project metadata - Dependency Management: Moved all production dependencies from setup.py to Poetry configuration
- Development Dependencies: Added testing dependencies as a separate development group
Testing Infrastructure
- Testing Framework: Set up pytest with comprehensive configuration
- Coverage Reporting: Configured pytest-cov with 80% coverage threshold
- Test Organization: Created structured test directories (
tests/unit/andtests/integration/) - Shared Fixtures: Comprehensive
conftest.pywith reusable testing utilities - Custom Markers: Added
unit,integration, andslowtest markers for test categorization
Configuration Details
- pytest configuration: Strict markers, verbose output, coverage reporting (HTML/XML)
- Coverage settings: Source code tracking, exclusion patterns, reporting thresholds
- Test discovery: Automatic test file pattern matching and collection
- Isolation: Automatic test isolation with temporary directories and mocked global state
Code Quality Improvements
- Import fixes: Updated all internal imports to use relative imports for proper package structure
- Module resolution: Fixed import issues that prevented proper testing
- Validation tests: Created comprehensive validation test suite to ensure infrastructure works
Development Environment
- Git integration: Updated
.gitignorewith testing artifacts, IDE files, and environment exclusions - Ready-to-use setup: Complete environment that allows immediate test development
- Documentation: Comprehensive fixtures and examples for common testing scenarios
Testing Infrastructure Components
Core Testing Dependencies
pytest = "^7.4.0" # Main testing framework
pytest-cov = "^4.1.0" # Coverage reporting
pytest-mock = "^3.11.1" # Mocking utilities
Available Fixtures
temp_dir- Temporary directory for file operationstemp_file- Pre-created temporary file for testingmock_config- Mock configuration dictionarymock_global_vars- Mocked global variables with automatic cleanupmock_meilisearch_client- Mock MeiliSearch client for testingsample_documents- Sample document data for indexing testssample_test_files- Pre-created test files with various extensionsmock_logger- Mock logger to suppress output during testsclean_environment- Environment variable isolationmock_requests- Mock HTTP requests library
Test Markers
@pytest.mark.unit- Unit tests@pytest.mark.integration- Integration tests@pytest.mark.slow- Slow-running tests
How to Run Tests
Install Dependencies
poetry install
Run All Tests
poetry run pytest
Run with Coverage Report
poetry run pytest --cov=achoz --cov-report=html
Run Specific Test Categories
poetry run pytest -m unit # Unit tests only
poetry run pytest -m integration # Integration tests only
poetry run pytest -m "not slow" # Skip slow tests
Coverage Reports
- Terminal: Real-time coverage shown during test runs
- HTML Report: Generated in
htmlcov/directory - XML Report: Generated as
coverage.xmlfor CI/CD integration
Validation
The infrastructure includes comprehensive validation tests that verify:
- All testing fixtures work correctly
- Module imports function properly
- Configuration is valid and complete
- Coverage reporting generates properly
- Test markers and categorization work
Current validation status: ✅ 18 passed, 1 skipped (OpenCV dependency optional)
Notes for Developers
Writing Tests
- Place unit tests in
tests/unit/ - Place integration tests in
tests/integration/ - Use the provided fixtures from
conftest.py - Mark tests appropriately with
@pytest.mark.unit,@pytest.mark.integration, etc. - Follow the 80% coverage threshold requirement
Development Workflow
- Write tests alongside code development
- Run tests frequently:
poetry run pytest - Check coverage:
poetry run pytest --cov-report=html - Use appropriate fixtures to mock external dependencies
- Ensure all tests pass before committing
Dependencies Management
- Lock file (
poetry.lock) is tracked in git - Use
poetry add <package>for production dependencies - Use
poetry add --group dev <package>for development dependencies - Use
poetry installto set up environment from scratch
This testing infrastructure provides a solid foundation for maintaining code quality and enabling confident development and refactoring of the achoz codebase.