Skip to content

feat: Set up comprehensive Python testing infrastructure with Poetry #55

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: develop
Choose a base branch
from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 25, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the Python project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and running tests with coverage reporting.

Changes Made

Package Management

  • Migrated to Poetry: Created pyproject.toml with all dependencies from requirements.txt
  • Preserved exact versions: Maintained the same dependency versions for compatibility
  • Added development dependencies: pytest, pytest-cov, and pytest-mock

Testing Configuration

  • pytest configuration:
    • Configured test discovery patterns
    • Set up coverage reporting with 80% threshold (currently set to 0% until source code tests are added)
    • Added HTML and XML coverage report generation
    • Configured custom markers: unit, integration, slow
    • Enabled strict mode and verbose output

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared pytest fixtures
├── test_infrastructure_validation.py  # Validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Fixtures Added

The conftest.py file includes these common fixtures:

  • temp_dir: Temporary directory management
  • temp_file: Temporary file creation
  • mock_config: Mock configuration dictionary
  • sample_data: Sample test data
  • mock_env_vars: Environment variable mocking
  • mock_http_response: HTTP response mocking
  • reset_environment: Automatic environment cleanup
  • clean_test_artifacts: Test artifact cleanup

Additional Updates

  • Updated .gitignore: Added entries for testing artifacts and Claude settings
  • Poetry scripts: Added test and tests commands for running pytest

How to Use

  1. Install Poetry (if not already installed):

    curl -sSL https://install.python-poetry.org | python3 -
  2. Install dependencies:

    poetry install
  3. Run tests:

    poetry run test
    # or
    poetry run tests
  4. Run specific test markers:

    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
  5. View coverage reports:

    • Terminal: Automatically shown after test runs
    • HTML: Open htmlcov/index.html in a browser
    • XML: Available at coverage.xml for CI integration

Notes

  • The coverage threshold is currently set to 0% to allow the infrastructure to be committed without source code tests. This should be updated to 80% once tests are written for the actual codebase.
  • The poetry.lock file is intentionally tracked in version control to ensure reproducible builds.
  • All pytest options are available when using the Poetry scripts (e.g., poetry run test -v -k test_name).

Next Steps

With this infrastructure in place, developers can now:

  1. Write unit tests in the tests/unit/ directory
  2. Write integration tests in the tests/integration/ directory
  3. Use the provided fixtures for common testing needs
  4. Monitor test coverage and work towards the 80% threshold

- Migrated from requirements.txt to Poetry package management
- Added pytest, pytest-cov, and pytest-mock as dev dependencies
- Configured pytest with coverage reporting (80% threshold)
- Created test directory structure with unit/integration subdirectories
- Added comprehensive pytest fixtures in conftest.py
- Set up Poetry script commands for running tests
- Added validation tests to verify infrastructure setup
- Updated .gitignore with testing and Claude-specific entries
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