Skip to content

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 29, 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 and organized test structure.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry configuration as the project's package manager
  • Testing Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies

Testing Configuration

  • pytest Settings: Configured pytest with:

    • Test discovery patterns for multiple naming conventions
    • Coverage reporting with HTML and XML output formats
    • Strict markers and configuration options
    • Custom markers for test categorization (unit, integration, slow)
    • Automatic output formatting and failure handling
  • Coverage Settings: Set up coverage.py with:

    • Source directory configuration
    • Exclusion patterns for test files, virtual environments, and generated code
    • Report formatting options and precision settings

Directory Structure

tests/
├── __init__.py
├── conftest.py
├── test_infrastructure_validation.py
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures (conftest.py)

Created comprehensive pytest fixtures including:

  • temp_dir: Temporary directory creation and cleanup
  • mock_config: Sample configuration dictionary
  • sample_data: Test data structures
  • mock_json_file, mock_text_file, mock_python_file: File creation helpers
  • env_vars: Environment variable management
  • capture_logs: Log capture utility
  • cleanup_test_files: Automatic test file cleanup

Additional Setup

  • Updated .gitignore with testing artifacts and Claude settings
  • Created validation tests to ensure the infrastructure works correctly
  • All 22 validation tests pass successfully

Running Tests

To run tests, use the following command:

poetry run pytest

Additional pytest options are available:

  • 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 --cov-report=html - Generate HTML coverage report

Dependencies Added

  • pytest (^8.3.4): Core testing framework
  • pytest-cov (^5.0.0): Coverage plugin for pytest
  • pytest-mock (^3.14.0): Mocking utilities integrated with pytest

Notes

  • Poetry lock file (poetry.lock) should be committed to version control for reproducible builds
  • Coverage threshold is currently disabled but can be enabled by adding --cov-fail-under=80 to pytest options
  • The infrastructure is ready for immediate test development - developers can start writing tests in the appropriate directories

- Configure Poetry as package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Set up pytest configuration with coverage reporting and custom markers
- Create testing directory structure (tests/unit/, tests/integration/)
- Add shared pytest fixtures for common testing patterns
- Update .gitignore with testing artifacts and Claude settings
- Add 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