Skip to content

feat: Set up Python testing infrastructure with Poetry #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 18, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the Python project using Poetry as the package manager and pytest as the testing framework. The infrastructure is ready for developers to immediately start writing tests without any additional setup.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry as the package manager
  • Dependencies: Added testing dependencies as development dependencies:
    • pytest (^7.4.0) - Main testing framework
    • pytest-cov (^4.1.0) - Coverage reporting
    • pytest-mock (^3.11.1) - Mocking utilities

Testing Configuration

  • Test Discovery: Configured pytest to discover tests in the tests/ directory
  • Coverage Settings:
    • 80% coverage threshold enforced
    • HTML and XML coverage reports generated
    • Coverage excludes test files and common non-code directories
  • Custom Markers:
    • unit: For fast, isolated unit tests
    • integration: For tests with dependencies
    • slow: For slow-running tests (skipped by default, use --runslow to include)

Directory Structure

/workspace/
├── pyproject.toml          # Poetry and testing configuration
├── .gitignore              # Updated with testing entries
├── coding_algorithms/      # Main package directory
│   └── __init__.py
└── tests/                  # Test directory
    ├── __init__.py
    ├── conftest.py         # Shared pytest fixtures
    ├── test_setup_validation.py  # Infrastructure validation tests
    ├── unit/               # Unit tests directory
    │   └── __init__.py
    └── integration/        # Integration tests directory
        └── __init__.py

Shared Fixtures (in conftest.py)

  • temp_dir: Creates temporary directory for test files
  • temp_file: Creates temporary file with content
  • mock_config: Provides mock configuration dictionary
  • sample_data: Sample data sets for algorithm testing
  • captured_output: Captures stdout/stderr for testing print statements
  • mock_env_vars: Sets mock environment variables
  • reset_sys_modules: Ensures clean imports between tests

Running Tests

After installing dependencies with poetry install, you can run tests using:

# Run all tests
poetry run test
# or
poetry run tests

# Run with specific options
poetry run pytest -v                    # Verbose output
poetry run pytest tests/unit/           # Run only unit tests
poetry run pytest -m integration        # Run only integration tests
poetry run pytest --runslow             # Include slow tests
poetry run pytest --cov-report=html     # Generate HTML coverage report

.gitignore Updates

Added entries for:

  • Testing artifacts (.pytest_cache/, coverage.xml, htmlcov/)
  • Python build artifacts
  • Virtual environments
  • IDE files
  • Claude-specific directory (.claude/*)

Notes

  • The infrastructure is set up but no actual unit tests for the codebase were written - this PR only provides the testing foundation
  • Poetry.lock file is intentionally not gitignored as it should be committed for reproducible builds
  • Coverage is configured to fail the build if it drops below 80%
  • All tests pass validation, confirming the infrastructure is properly configured

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures for common testing scenarios
  4. Run tests with coverage reporting to ensure code quality

- Configure Poetry as package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Set up comprehensive pytest configuration with coverage
- Create test directory structure (tests/unit, tests/integration)
- Add shared fixtures in conftest.py for common testing needs
- Configure coverage reporting with 80% threshold
- Add custom test markers (unit, integration, slow)
- Update .gitignore with testing and Claude-specific entries
- Create validation tests to verify infrastructure setup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant