Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 1, 2025

Add Comprehensive Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the OPUS project, providing developers with a ready-to-use testing environment that follows Python best practices.

Key Components Added:

Poetry Package Manager: Complete project configuration with dependency management
pytest Configuration: Comprehensive testing setup with coverage reporting and custom markers
Testing Directory Structure: Organized tests/ directory with unit/ and integration/ subdirectories
Shared Fixtures: Extensive collection of reusable test fixtures in conftest.py
Coverage Reporting: HTML and XML coverage reports with 80% threshold requirement
Development Tools: Black, isort, flake8, and mypy for code quality

Testing Infrastructure Features:

  • Test Discovery: Automatic detection of test_*.py files
  • Custom Markers: @pytest.mark.unit, @pytest.mark.integration, @pytest.mark.slow, @pytest.mark.gpu
  • Coverage Analysis: Source code coverage with exclusions for test files and CUDA extensions
  • Shared Fixtures: Mock models, sample data, temporary directories, camera parameters, LiDAR data
  • Validation Tests: Infrastructure verification tests that run without external dependencies

Configuration Files:

  • pyproject.toml: Poetry configuration with pytest and coverage settings
  • tests/conftest.py: Comprehensive shared fixtures for testing
  • tests/README.md: Complete testing documentation and usage instructions
  • Updated .gitignore: Testing artifacts and Claude Code settings

Instructions for Running Tests

Option 1: With Poetry (Recommended)

# Install dependencies
poetry install

# Run all tests  
poetry run test
# or
poetry run tests

# Run with coverage
poetry run pytest --cov

Option 2: Basic Validation (No Dependencies Required)

# Run infrastructure validation
python3 tests/test_basic_infrastructure.py

Option 3: With pip

# Create virtual environment and install dependencies
python3 -m venv venv
source venv/bin/activate
pip install pytest pytest-cov pytest-mock torch numpy

# Run tests
pytest

Test Organization

  • Unit Tests: Place in tests/unit/ for fast, isolated component tests
  • Integration Tests: Place in tests/integration/ for multi-component tests
  • Markers: Use @pytest.mark.unit, @pytest.mark.integration, etc. for categorization
  • Fixtures: Leverage shared fixtures from conftest.py for common test data

Coverage Requirements

  • Minimum 80% code coverage required
  • HTML reports generated in htmlcov/
  • XML reports generated as coverage.xml
  • Excludes test files, CUDA extensions, and build artifacts

Development Dependencies

The testing infrastructure includes development tools:

  • pytest: Main testing framework
  • pytest-cov: Coverage reporting
  • pytest-mock: Enhanced mocking capabilities
  • black, isort: Code formatting
  • flake8: Linting
  • mypy: Type checking

Notes

  • Poetry configuration is optimized for the OPUS project dependencies
  • Testing works with or without ML dependencies installed
  • Infrastructure validated on Python 3.8+
  • Lock files excluded from .gitignore as intended

This infrastructure provides a solid foundation for test-driven development and ensures code quality for the OPUS occupancy prediction project.

🤖 Generated with Claude Code

- Set up Poetry package manager with pyproject.toml configuration
- Configure pytest with coverage reporting, custom markers, and strict options
- Create testing directory structure (tests/unit/, tests/integration/)
- Add comprehensive shared fixtures in conftest.py for mocks and test data
- Implement validation tests to verify infrastructure setup
- Update .gitignore with testing-related entries and Claude Code settings
- Configure coverage reporting with 80% threshold and HTML/XML output
- Set up Poetry scripts for easy test execution (poetry run test/tests)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
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