WordleSolver icon indicating copy to clipboard operation
WordleSolver copied to clipboard

feat: Set up comprehensive Python testing infrastructure

Open llbbl opened this issue 5 months ago • 0 comments

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.toml with 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, and slow markers 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_dir and temp_file for file system testing
  • sample_words for Wordle-specific test data
  • wordle_game and solver_instance mock objects
  • mock_print and captured_stdout for output testing
  • game_config for 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.lock for 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.slow for 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:

  1. Start writing unit tests in tests/unit/
  2. Create integration tests in tests/integration/
  3. Utilize the shared fixtures from conftest.py
  4. Run tests with coverage reporting
  5. 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.

llbbl avatar Sep 03 '25 15:09 llbbl