Skip to content

feat: Add comprehensive Python testing infrastructure with Poetry#81

Open
llbbl wants to merge 1 commit intolmb-freiburg:masterfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Add comprehensive Python testing infrastructure with Poetry#81
llbbl wants to merge 1 commit intolmb-freiburg:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Jun 30, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the DeMoN (Depth Motion Network) project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry configuration as the project's package manager
  • Dependencies: Migrated core dependencies (tensorflow, numpy, pillow, matplotlib) to Poetry
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies

Testing Configuration

  • Pytest Configuration: Configured pytest with:

    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting with HTML and XML outputs
    • Custom markers: unit, integration, and slow
    • Strict marker enforcement to prevent typos
  • Coverage Configuration: Set up coverage.py with:

    • Source directory targeting python/depthmotionnet
    • Exclusion patterns for test files and boilerplate code
    • HTML and XML report generation
    • Coverage threshold set to 0% for initial setup (can be increased as tests are added)

Directory Structure

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

Shared Fixtures (conftest.py)

Created comprehensive fixtures for common testing needs:

  • temp_dir: Temporary directory management
  • mock_config: Mock configuration object
  • sample_image_pair: Creates test image pairs
  • sample_depth_map: Generates test depth maps
  • sample_camera_matrix: Provides test camera intrinsics
  • sample_rotation_translation: Test transformation matrices
  • reset_tensorflow: Clears TF session between tests
  • mock_dataset: Creates mock dataset structure
  • capture_stdout: Captures print output for testing

Development Commands

Both poetry run test and poetry run tests are configured to run the test suite with all pytest options available.

Additional Updates

  • Updated .gitignore: Added patterns for:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, coverage.xml)
    • Claude settings (.claude/*)
    • Python artifacts (pycache/, *.py[cod])
    • Virtual environments (venv/, .venv/, etc.)
    • IDE files (.vscode/, .idea/)
    • TensorFlow/model files (*.pb, *.h5, checkpoints)

How to Use

  1. Install dependencies:

    poetry install
  2. Run all 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. Run with coverage:
    Coverage is automatically generated when running tests. View reports:

    • Terminal: Coverage summary is shown after test run
    • HTML: Open htmlcov/index.html in a browser
    • XML: Available at coverage.xml for CI integration

Validation

The setup includes validation tests in test_setup_validation.py that verify:

  • pytest is properly installed
  • The project module can be imported
  • All markers work correctly
  • Fixtures are available and functional
  • Test directories exist

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

Next Steps

Developers can now:

  1. Write unit tests in the tests/unit/ directory
  2. Write integration tests in the tests/integration/ directory
  3. Use the provided fixtures for common testing scenarios
  4. Gradually increase the coverage threshold as more tests are added

- Set up Poetry as package manager with pyproject.toml configuration
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with markers (unit, integration, slow) and coverage reporting
- Create test directory structure with shared fixtures in conftest.py
- Update .gitignore with testing and development patterns
- Add validation tests to verify testing 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