uncurled
uncurled copied to clipboard
feat: Set up Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR establishes a complete testing infrastructure for the Python project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry Setup: Created
pyproject.tomlwith Poetry configuration - Dependencies: Added testing dependencies as development dependencies:
pytest(^8.0.0) - Core testing frameworkpytest-cov(^5.0.0) - Coverage reportingpytest-mock(^3.14.0) - Mocking utilities
Testing Configuration
-
pytest Configuration:
- Test discovery patterns for
test_*.pyand*_test.pyfiles - Strict markers and configuration
- Custom markers:
unit,integration,slow - Verbose output with detailed failure reports
- Test discovery patterns for
-
Coverage Configuration:
- 80% coverage threshold requirement
- HTML and XML report generation
- Exclusion patterns for test files, virtual environments, and boilerplate code
- Branch coverage tracking
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_setup_validation.py # Infrastructure validation
├── unit/
│ ├── __init__.py
│ └── test_uni.py # Example unit test
└── integration/
└── __init__.py
Testing Fixtures
Created comprehensive shared fixtures in conftest.py:
temp_dir- Temporary directory managementtemp_file- Temporary file creationmock_env_vars- Environment variable mockingsample_markdown_file- Test data generationsample_config- Configuration mockingmock_file_system- File system structure mockingcapture_stdout- Output capturing
Development Commands
Configured Poetry scripts for running tests:
poetry run test- Run all testspoetry run tests- Alternative command (both work)
Additional Setup
- Updated
.gitignorewith Python and testing patterns - Added Claude settings exclusion (
.claude/*) - Created validation tests to verify the infrastructure
How to Use
-
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 - -
Install Dependencies:
poetry install -
Run Tests:
poetry run test # or poetry run tests -
Run Specific Test Categories:
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 -
View Coverage Reports:
- Terminal: Automatically shown after test run
- HTML: Open
htmlcov/index.htmlin browser - XML: Available at
coverage.xmlfor CI integration
Notes
- The infrastructure is ready for immediate test development
- Coverage threshold is set to 80% but can be adjusted in
pyproject.toml - All pytest options are available through the Poetry commands
- The
poetry.lockfile is NOT gitignored and should be committed for reproducible builds - Validation tests are included to ensure the infrastructure works correctly