Skip to content

feat: Set up Python testing infrastructure with Poetry and pytest - #96

Open
llbbl wants to merge 1 commit into
mbrossar:masterfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up Python testing infrastructure with Poetry and pytest#96
llbbl wants to merge 1 commit into
mbrossar:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl

@llbbl llbbl commented Jun 28, 2025

Copy link
Copy Markdown

Python Testing Infrastructure Setup

Summary

This PR sets up 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 maintaining tests with proper organization, coverage reporting, and development tooling.

Changes Made

Package Management

  • Poetry Configuration: Set up Poetry as the package manager with pyproject.toml
  • Dependency Management: Added numpy as a project dependency (detected from existing code usage)
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Framework Setup

  • pytest Configuration:

    • Configured test discovery patterns
    • Set coverage threshold at 80%
    • Added strict markers and comprehensive reporting options
    • Created custom test markers: unit, integration, slow
  • Coverage Configuration:

    • HTML and XML report generation
    • Source code coverage tracking
    • Exclusion patterns for test files and virtual environments

Directory Structure

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

Testing Fixtures (conftest.py)

Created comprehensive shared fixtures for common testing needs:

  • temp_dir and temp_file: Temporary file/directory management
  • mock_config: Mock configuration objects
  • sample_data: Sample numpy data generation
  • mock_dataset: Mock dataset for ML testing
  • numpy_array_fixture: Common numpy arrays
  • torch_tensor_fixture: PyTorch tensors (when available)
  • reset_random_seeds: Reproducible test runs
  • capture_stdout: Output capture for testing print statements
  • mock_file_operations: Mock file I/O operations
  • time_tracker: Performance measurement

Development Experience

  • Poetry Scripts: Added poetry run test and poetry run tests commands
  • GitIgnore Updates: Added patterns for:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
    • Claude settings (.claude/*)
    • Virtual environments and build artifacts
    • IDE files

How to Use

  1. Install dependencies:

    poetry install
  2. Run tests:

    poetry run test
    # or
    poetry run tests
    # or directly with pytest
    poetry run pytest
  3. 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
  4. View coverage reports:

    • Terminal: Included in test output
    • HTML: Open htmlcov/index.html after running tests
    • XML: Available at coverage.xml for CI integration

Validation

The setup includes validation tests that verify:

  • Project structure is correctly configured
  • All dependencies can be imported
  • Custom fixtures work as expected
  • Test markers are properly configured
  • Coverage reporting functions correctly

All validation tests pass successfully.

Notes

  • The project had syntax warnings in src/train_torch_filter.py that should be addressed separately
  • Coverage is currently at 0% as no actual unit tests for the source code have been written yet
  • The infrastructure is ready for immediate test development

- Configure Poetry as package manager with pyproject.toml
- Add testing dependencies: pytest, pytest-cov, pytest-mock
- Set up comprehensive pytest configuration with coverage thresholds
- Create testing directory structure (tests/unit, tests/integration)
- Configure coverage reporting (HTML, XML, terminal)
- Add pytest markers for unit, integration, and slow tests
- Create shared fixtures in conftest.py for common testing needs
- Update .gitignore with testing and Claude-related patterns
- Add numpy as project dependency
- 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