Skip to content

feat: Add comprehensive Python testing infrastructure with Poetry#73

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

feat: Add comprehensive Python testing infrastructure with Poetry#73
llbbl wants to merge 1 commit into
dwofk:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Jun 24, 2025

Add Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the FastDepth project using Poetry as the package manager and pytest as the testing framework. The setup provides a ready-to-use environment where developers can immediately start writing tests with proper tooling, configuration, and shared fixtures.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry as the package manager
  • Dependencies: Migrated existing Python dependencies from README requirements
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Configuration

  • pytest Configuration:

    • Test discovery patterns for test_*.py and *_test.py files
    • Custom markers: unit, integration, and slow
    • Strict mode enabled for better error detection
    • Verbose output with short traceback format
  • Coverage Configuration:

    • 80% coverage threshold enforced
    • HTML reports generated in htmlcov/
    • XML reports for CI integration
    • Proper exclusions for test files and virtual environments

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • mock_config: Mock configuration object
  • sample_rgb_image: Sample RGB image array
  • sample_depth_map: Sample depth map array
  • sample_batch: PyTorch batch data
  • mock_model: Mock PyTorch model
  • mock_dataloader: Mock dataloader
  • device: PyTorch device selection
  • mock_checkpoint: Mock checkpoint file
  • mock_hdf5_file: Mock HDF5 data file
  • reset_torch_state: Auto-cleanup for PyTorch
  • capture_stdout: Stdout capture utility

Other Updates

  • Updated .gitignore: Added entries for:
    • Testing artifacts (.pytest_cache/, coverage files)
    • Virtual environments
    • Poetry lock file
    • Claude settings (.claude/*)
    • IDE files and build artifacts

Running Tests

Install Dependencies

poetry install

Run All Tests

poetry run pytest

Run Tests with Options

# Run only unit tests
poetry run pytest -m unit

# Run without coverage
poetry run pytest --no-cov

# Run specific test file
poetry run pytest tests/test_infrastructure_validation.py

# Run with specific verbosity
poetry run pytest -vv

View Coverage Report

After running tests, open htmlcov/index.html in a browser to view the detailed coverage report.

Notes

  • The infrastructure is set up to work with PyTorch-based code
  • Coverage threshold is set to 80% but only applies to test files for now
  • The validation tests confirm that all components are properly configured
  • Both poetry run test and poetry run tests commands are available (though currently simplified to use pytest directly)

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures for common testing scenarios
  4. Run tests with coverage reporting
  5. Mark slow tests appropriately for selective execution

- Set up Poetry package management with pyproject.toml configuration
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Configure pytest with markers for unit, integration, and slow tests
- Set up coverage reporting with 80% threshold and multiple output formats
- Create test directory structure with proper __init__.py files
- Add comprehensive conftest.py with shared fixtures for testing
- Update .gitignore with testing and Claude-specific entries
- Create infrastructure validation tests to ensure setup works correctly
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