MailRipV3
MailRipV3 copied to clipboard
feat: Set up comprehensive Python testing infrastructure with Poetry
Python Testing Infrastructure Setup
Summary
This PR establishes a comprehensive 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
- ✅ Detected and utilized existing Poetry configuration
- ✅ Added testing dependencies as development dependencies (not production)
Testing Dependencies Added
pytest(^8.3.3) - Main testing frameworkpytest-cov(^5.0.0) - Coverage reporting with HTML/XML outputpytest-mock(^3.14.0) - Mocking utilities for unit tests
Testing Configuration (pyproject.toml)
-
pytest settings:
- Test discovery patterns configured for
test_*.pyand*_test.py - Coverage reporting with 80% threshold requirement
- HTML and XML coverage reports generation
- Strict markers enabled for better test organization
- Custom markers defined:
unit,integration,slow
- Test discovery patterns configured for
-
Coverage settings:
- Source directory set to
src/ - Exclusions configured for test files, migrations, and boilerplate code
- Branch coverage enabled
- Multiple report formats (terminal, HTML, XML)
- Source directory set to
Directory Structure Created
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_validation.py # Infrastructure validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (conftest.py)
temp_dir- Temporary directory with automatic cleanuptemp_file- Create temporary files for testingmock_config- Mock configuration objectmock_logger- Mock logger for testing loggingsample_json_data- Sample JSON data fixturejson_file- Create temporary JSON filesmock_env_vars- Mock environment variablesmock_http_response- Mock HTTP responsesmock_database_connection- Mock database connectionscapture_stdout- Capture print output for testingreset_modules- Clean module state between tests
Development Commands
Both commands are now available via Poetry:
poetry run test- Run all testspoetry run tests- Alternative command (both work identically)
All standard pytest options are available (e.g., poetry run test -v, poetry run test -k unit)
.gitignore Updates
Added comprehensive Python and testing-related entries:
- Testing artifacts (
.pytest_cache/,.coverage,htmlcov/,coverage.xml) - Python artifacts (
__pycache__/,*.py[cod],.eggs/) - Virtual environments (
venv/,.venv/) - IDE files (
.vscode/,.idea/) - Claude settings (
.claude/) - Build artifacts and temporary files
How to Use
Install Dependencies
poetry install
Run Tests
# Run all tests
poetry run test
# Run with verbose output
poetry run test -v
# Run only unit tests
poetry run test -m unit
# Run tests with coverage report
poetry run test --cov
# Run specific test file
poetry run test tests/test_validation.py
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, or@pytest.mark.slow
Coverage Reports
After running tests, coverage reports are available in:
- Terminal output (shows missing lines)
htmlcov/index.html- Interactive HTML reportcoverage.xml- XML report for CI/CD integration
Validation
The infrastructure has been validated with 18 tests that verify:
- All dependencies are properly installed
- Directory structure is correctly created
- All fixtures work as expected
- Test markers are properly configured
- Poetry scripts function correctly
Notes
- The project uses Poetry for dependency management, which provides better dependency resolution and lock file management compared to pip
- Coverage threshold is set to 80% - tests will fail if coverage drops below this
- The
poetry.lockfile should be committed to ensure reproducible builds - No actual unit tests for the codebase were written - only infrastructure setup and validation tests