WordleSolver
WordleSolver copied to clipboard
feat: Set up comprehensive Python testing infrastructure
Set up comprehensive Python testing infrastructure
Summary
This PR establishes a complete testing infrastructure for the Wordle project using modern Python development tools and best practices. The setup provides a robust foundation for writing and running tests while ensuring code quality through coverage reporting.
Changes Made
Package Management
- ✅ Poetry Configuration: Added
pyproject.tomlwith Poetry setup for dependency management - ✅ Testing Dependencies: Installed pytest, pytest-cov, and pytest-mock as development dependencies
- ✅ Python 3.8+ Compatibility: Configured for Python 3.8 and above
Testing Framework Configuration
- ✅ pytest Settings: Configured with strict markers, verbose output, and proper test discovery
- ✅ Coverage Reporting: Set up with 80% threshold, HTML/XML/terminal reporting
- ✅ Custom Test Markers: Added
unit,integration, andslowmarkers for test categorization - ✅ Comprehensive Coverage Exclusions: Configured to ignore test files, virtual environments, and generated files
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and test configuration
├── unit/
│ └── __init__.py
├── integration/
│ └── __init__.py
└── test_setup_validation.py # Validation tests for infrastructure
Shared Test Fixtures
The tests/conftest.py file provides reusable fixtures including:
-
temp_dirandtemp_filefor file system testing -
sample_wordsfor Wordle-specific test data -
wordle_gameandsolver_instancemock objects -
mock_printandcaptured_stdoutfor output testing -
game_configfor standard game settings
Development Environment
- ✅ Updated .gitignore: Added comprehensive patterns for Python development, testing, and IDE files
- ✅ Virtual Environment: Poetry automatically manages virtual environment and dependencies
- ✅ Lock File: Generated
poetry.lockfor reproducible builds (not gitignored)
Running Tests
Basic Test Commands
# Install dependencies
poetry install
# Run all tests
poetry run pytest
# Run tests without coverage
poetry run pytest --no-cov
# Run only unit tests
poetry run pytest -m unit
# Run with verbose output
poetry run pytest -v
Coverage Reporting
# Generate HTML coverage report
poetry run pytest --cov-report=html
# View coverage in terminal
poetry run pytest --cov-report=term-missing
# Generate XML coverage for CI/CD
poetry run pytest --cov-report=xml
Test Organization
-
Unit Tests: Place in
tests/unit/for testing individual functions/classes -
Integration Tests: Place in
tests/integration/for testing component interactions -
Mark Slow Tests: Use
@pytest.mark.slowfor tests that take significant time
Validation
The infrastructure includes comprehensive validation tests (test_setup_validation.py) that verify:
- ✅ Python version compatibility
- ✅ All testing dependencies are installed and accessible
- ✅ Project structure is correct
- ✅ Configuration files are valid
- ✅ Shared fixtures work properly
- ✅ Test markers function correctly
- ✅ Mocking capabilities work
All validation tests pass successfully, confirming the testing infrastructure is ready for use.
Next Steps
Developers can now:
- Start writing unit tests in
tests/unit/ - Create integration tests in
tests/integration/ - Utilize the shared fixtures from
conftest.py - Run tests with coverage reporting
- Follow the established patterns for consistent testing practices
Dependencies Added
-
pytest ^7.4.0- Main testing framework -
pytest-cov ^4.1.0- Coverage reporting plugin -
pytest-mock ^3.11.1- Enhanced mocking utilities
All dependencies are installed as development dependencies and will not affect production deployments.