Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 14, 2025

Add Testing Infrastructure for Mask R-CNN PyTorch

Summary

This PR establishes a comprehensive testing infrastructure for the Mask R-CNN PyTorch project using Poetry for dependency management and pytest as the testing framework. The setup provides a ready-to-use environment where developers can immediately start writing and running tests.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry as the package manager
  • Dependency Migration: Migrated existing dependencies from the project into Poetry format
  • Development Dependencies: Added pytest (^7.4.0), pytest-cov (^4.1.0), pytest-mock (^3.11.1)
  • Additional Tools: Included black, isort, flake8, and mypy for code quality

Testing Configuration

  • pytest Settings:
    • Configured test discovery patterns
    • Set 80% coverage threshold
    • Added strict markers and configuration
    • Enabled verbose output and colored reports
  • Coverage Configuration:
    • HTML reports in htmlcov/
    • XML reports for CI integration
    • Excluded test files, migrations, and virtual environments from coverage
  • Test Markers:
    • @pytest.mark.unit for unit tests
    • @pytest.mark.integration for integration tests
    • @pytest.mark.slow for slow-running tests

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures (minimal version)
├── conftest_full.py.bak     # Full fixtures requiring all dependencies
├── README.md                # Testing documentation
├── unit/
│   └── __init__.py
├── integration/
│   └── __init__.py
└── test_basic_infrastructure.py  # Validation tests

Test Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir: Temporary directory creation
  • mock_config: Mock Mask R-CNN configuration
  • capture_stdout: Stdout capture for testing prints
  • mock_file_system: Mock directory structure
  • environment_variables: Test environment setup

Additional fixtures in conftest_full.py.bak (requires full dependencies):

  • Image and tensor fixtures
  • Mock models and datasets
  • GPU/device detection
  • Sample batch data

Poetry Scripts

Added convenient test commands:

poetry run test    # Run all tests
poetry run tests   # Alternative command

Other Updates

  • .gitignore: Updated with testing artifacts, coverage files, and .claude/*
  • Validation Tests: Created tests to verify the infrastructure works correctly
  • Documentation: Added comprehensive README in the tests directory

How to Use

  1. Install dependencies:

    poetry install --with dev
  2. Run tests:

    poetry run test
    # or with specific options
    poetry run test -v -m unit --no-cov
  3. Generate coverage reports:

    poetry run test --cov-report=html
    # Open htmlcov/index.html in browser

Notes

  • The current conftest.py is a minimal version that works without all project dependencies
  • Once all dependencies are installed, developers can replace it with conftest_full.py.bak for additional fixtures
  • Poetry lock file is not committed as per .gitignore configuration
  • All pytest options are available through the Poetry scripts

Testing the Setup

The PR includes test_basic_infrastructure.py which validates:

  • All testing tools are properly installed
  • Fixtures work correctly
  • Test markers function as expected
  • Poetry commands are configured
  • Coverage settings are applied

All validation tests pass successfully, confirming the infrastructure is ready for use.

- Set up Poetry for dependency management with pyproject.toml
- Configure pytest with coverage, markers, and custom settings
- Add testing dependencies: pytest, pytest-cov, pytest-mock
- Create test directory structure with unit/integration subdirs
- Add comprehensive test fixtures in conftest.py
- Configure 80% coverage threshold with HTML/XML reporting
- Add test markers for unit, integration, and slow tests
- Create validation tests to verify infrastructure setup
- Update .gitignore with testing and Claude-related entries
- Add Poetry scripts for 'test' and 'tests' commands
- Include testing README with usage instructions
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