V2RSS
V2RSS copied to clipboard
feat: Set up comprehensive Python testing infrastructure with Poetry
Add Python Testing Infrastructure
Summary
This PR sets up 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
- Initialized Poetry as the package manager by creating
pyproject.toml - Migrated all dependencies from
requirements.txtto Poetry format - Added testing dependencies as development dependencies:
pytest(^7.4.0) - Main testing frameworkpytest-cov(^4.1.0) - Coverage reportingpytest-mock(^3.11.1) - Mocking utilities
Testing Configuration
- Configured pytest in
pyproject.tomlwith:- Test discovery patterns for
test_*.pyand*_test.pyfiles - Coverage reporting with HTML and XML outputs
- Strict markers and configuration
- Custom markers:
unit,integration,slow - Coverage source set to
srcdirectory
- Test discovery patterns for
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── test_setup_validation.py # Validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (conftest.py)
temp_dir- Creates temporary directories for teststemp_file- Creates temporary filesmock_config- Provides mock configuration dictionarymock_yaml_config- Creates temporary YAML config filesmock_env_vars- Sets up mock environment variablesclean_env- Removes specific environment variablesmock_request_data- Provides mock HTTP request datasample_data_list- Sample test datacapture_logs- Helper for log assertionsmock_datetime- Mock datetime for consistent testing- Custom pytest options to handle slow tests with
--run-slowflag
Build Configuration
- Updated
.gitignorewith:- Testing artifacts (
.pytest_cache/,coverage.xml,htmlcov/) - Claude settings (
.claude/) - Note to commit
poetry.lockfile - IDE and OS-specific files
- Testing artifacts (
How to Use
Install Dependencies
poetry install
Run Tests
Both commands work and run pytest:
poetry run test
poetry run tests
Run Specific Tests
# Run only unit tests
poetry run pytest -m unit
# Run integration tests
poetry run pytest -m integration
# Run slow tests (normally skipped)
poetry run pytest --run-slow
# Run with verbose output
poetry run pytest -v
Coverage Reports
- Coverage is automatically calculated when running tests
- HTML report:
htmlcov/index.html - XML report:
coverage.xml - Terminal report shows uncovered lines
Writing New Tests
- Create test files in
tests/unit/ortests/integration/ - Name files as
test_*.pyor*_test.py - Use fixtures from
conftest.pyfor common needs - Mark tests appropriately:
@pytest.mark.unit def test_example(): assert True
Notes
- Coverage threshold is currently set to 0% since this PR only sets up infrastructure
- The validation test file (
test_setup_validation.py) verifies the setup works correctly - All Poetry commands should be run from the project root
- The
poetry.lockfile should be committed to ensure reproducible builds