feat: set up comprehensive Python testing infrastructure with Poetry
Set up Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the P3 (Programming Puzzles and Code Competitions) 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: Migrated core dependencies from existing requirements files
- Development Dependencies: Added pytest, pytest-cov, and pytest-mock
Testing Configuration
-
pytest Configuration:
- Test discovery patterns for
test_*.pyand*_test.pyfiles - Coverage reporting with HTML and XML output formats
- Custom markers for unit, integration, and slow tests
- Strict mode options for better test quality
- Test discovery patterns for
-
Coverage Configuration:
- Source directories:
generatorsandsolvers - Exclusions for test files and common patterns
- Detailed reporting with line-by-line coverage
- Source directories:
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── test_infrastructure_validation.py # Validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (conftest.py)
-
temp_dir: Temporary directory for test files -
temp_file: Temporary file with test content -
mock_config: Mock configuration dictionary -
sample_puzzle_data: Sample puzzle data for testing -
sample_code_snippet: Sample code for testing -
mock_environment_variables: Mock environment variables -
project_root,generators_path,solvers_path: Path fixtures -
clean_imports: Import cleanup for test isolation -
reset_random_seed: Reproducible random seeds
Poetry Commands
-
poetry run test- Run all tests -
poetry run tests- Alternative command (both work)
Additional Configuration
- Updated
.gitignorewith:- Testing artifacts (
.pytest_cache/,coverage.xml,htmlcov/) - Claude settings (
.claude/*) - Note:
poetry.lockis NOT ignored (should be in version control)
- Testing artifacts (
Testing the Infrastructure
Installation
poetry install
Running Tests
# Run all tests
poetry run test
# Run with specific markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"
# Run with coverage
poetry run pytest --cov
# Run specific test file
poetry run pytest tests/test_infrastructure_validation.py
Validation Tests
The PR includes comprehensive validation tests that verify:
- pytest is properly installed and configured
- Project modules can be imported
- All fixtures are available and working
- Custom markers are configured
- Coverage reporting is set up
- Various pytest features work correctly
Notes
-
orderedset Dependency: The
orderedsetpackage from the original requirements had build issues on the current platform. It has been commented out in favor of using Python's built-inOrderedDictwhen needed. -
Coverage Thresholds: The 80% coverage threshold has been temporarily disabled in the configuration since this PR only sets up the infrastructure without implementing actual tests for the codebase.
-
Deprecation Warnings: Some existing code has deprecation warnings (invalid escape sequences). These are from the existing codebase and should be addressed in a separate PR.
Next Steps
With this testing infrastructure in place, developers can now:
- Write unit tests for individual modules
- Create integration tests for complex workflows
- Add performance benchmarks using the slow marker
- Monitor code coverage and improve test quality
- Use the shared fixtures to reduce test boilerplate
The infrastructure is designed to be extensible and can be enhanced with additional fixtures, plugins, and configurations as needed.
@microsoft-github-policy-service agree