Skip to content

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

Open
llbbl wants to merge 1 commit intofenglinglwb:mainfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up comprehensive Python testing infrastructure with Poetry#130
llbbl wants to merge 1 commit intofenglinglwb:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 28, 2025

Add Python Testing Infrastructure with Poetry

Summary

This PR sets up a comprehensive testing infrastructure for the MAT (Mask-Aware Transformer) 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 proper coverage reporting and organization.

Changes Made

Package Management

  • Migrated to Poetry: Created pyproject.toml with all dependencies from requirements.txt
  • Lock file: Generated poetry.lock for reproducible builds
  • Development dependencies: Added pytest, pytest-cov, and pytest-mock

Testing Configuration

  • pytest settings: Configured in pyproject.toml with:
    • Test discovery patterns
    • Coverage reporting (term, HTML, XML)
    • 80% coverage threshold (configurable)
    • Custom markers: unit, integration, slow
    • Verbose output and strict mode

Directory Structure

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

Testing Fixtures (in conftest.py)

  • temp_dir: Temporary directory management
  • mock_config: Configuration dictionary for testing
  • sample_image, sample_mask: NumPy arrays for image testing
  • sample_tensor_image, sample_tensor_mask: PyTorch tensors
  • mock_model: Simple PyTorch model for testing
  • mock_dataset_path: Creates mock dataset structure
  • device: CPU/GPU device selection
  • reset_random_seeds: Ensures reproducible tests

Additional Setup

  • Updated .gitignore with testing artifacts and Poetry files
  • Created validation tests to verify the infrastructure works
  • Configured Poetry scripts for easy test execution

How to Use

  1. Install dependencies:

    poetry install
  2. Run tests:

    poetry run test
    # or
    poetry run tests
  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: Automatically shown after test run
    • HTML: Open htmlcov/index.html in browser
    • XML: Available at coverage.xml for CI/CD integration

Notes

  • The coverage threshold is initially set to 80% but can be adjusted in pyproject.toml
  • The infrastructure validation tests all pass, confirming proper setup
  • Poetry lock file is committed for reproducible environments
  • No actual unit tests for the codebase were written - only infrastructure setup

Next Steps

Developers can now immediately start writing tests for:

  • Model components (networks/)
  • Loss functions (losses/)
  • Metrics (metrics/)
  • Data processing (datasets/)
  • Training loops (training/)
  • Utilities (torch_utils/, dnnlib/)

- Migrate project to Poetry package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting (HTML/XML), markers, and settings
- Create tests/ directory structure with unit/integration subdirectories
- Add comprehensive conftest.py with fixtures for testing ML/CV code
- Create validation tests to verify infrastructure setup
- Update .gitignore with testing and Poetry-related entries
- Configure Poetry scripts for 'poetry run test' and 'poetry run tests'
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