feat: Set up comprehensive Python testing infrastructure with Poetry #22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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 testsTesting Configuration (
pyproject.toml
)pytest settings:
test_*.py
and*_test.py
unit
,integration
,slow
Coverage settings:
src/
Directory Structure Created
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 testsDevelopment 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
UpdatesAdded comprehensive Python and testing-related entries:
.pytest_cache/
,.coverage
,htmlcov/
,coverage.xml
)__pycache__/
,*.py[cod]
,.eggs/
)venv/
,.venv/
).vscode/
,.idea/
).claude/
)How to Use
Install Dependencies
Run Tests
Writing Tests
tests/unit/
tests/integration/
conftest.py
@pytest.mark.unit
,@pytest.mark.integration
, or@pytest.mark.slow
Coverage Reports
After running tests, coverage reports are available in:
htmlcov/index.html
- Interactive HTML reportcoverage.xml
- XML report for CI/CD integrationValidation
The infrastructure has been validated with 18 tests that verify:
Notes
poetry.lock
file should be committed to ensure reproducible builds