Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 1, 2025

Set Up Complete Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the StructVIO project, providing a robust foundation for writing and running tests. The setup follows Python testing best practices and includes all necessary tooling for development and CI/CD integration.

Changes Made

Package Management

  • Poetry Setup: Configured Poetry as the package manager with pyproject.toml
  • Dependencies: Added core dependencies (numpy, evo) and testing dependencies (pytest, pytest-cov, pytest-mock)
  • Lock File: Generated poetry.lock for reproducible builds

Testing Configuration

  • pytest Configuration: Comprehensive pytest setup in pyproject.toml with:
    • Test discovery patterns (test_*.py, *_test.py)
    • Coverage reporting (80% threshold, HTML/XML output)
    • Custom markers (unit, integration, slow)
    • Strict options and verbose output
  • Coverage Settings: Configured coverage exclusions and reporting formats

Project Structure

  • Testing Directories: Created proper structure:
    tests/
    ├── __init__.py
    ├── conftest.py           # Shared fixtures
    ├── test_setup_validation.py  # Infrastructure validation
    ├── unit/
    │   └── __init__.py
    └── integration/
        └── __init__.py
    

Shared Testing Infrastructure

  • Fixtures: Comprehensive fixture library in conftest.py:
    • temp_dir: Temporary directories with cleanup
    • mock_structvio_output: Sample VIO trajectory data
    • mock_euroc_groundtruth: EuRoC dataset groundtruth
    • mock_numpy_arrays: Mathematical test data
    • File operation helpers

Development Environment

  • .gitignore: Added testing artifacts, virtual environments, IDE files, and Claude settings
  • Validation Tests: Created comprehensive test suite to verify infrastructure functionality

Testing Infrastructure Components

1. Test Execution

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov=scripts

# Run specific test types
poetry run pytest -m unit        # Unit tests only
poetry run pytest -m integration # Integration tests only
poetry run pytest -m slow        # Slow tests only

2. Coverage Reporting

  • Terminal: Displays missing lines and coverage percentages
  • HTML Report: Generated in htmlcov/ directory for detailed analysis
  • XML Report: coverage.xml for CI/CD integration
  • Threshold: Configured for 80% minimum coverage

3. Available Fixtures

  • temp_dir: Clean temporary directory for each test
  • mock_structvio_output: Sample VIO trajectory data
  • mock_euroc_groundtruth: EuRoC groundtruth data
  • mock_numpy_arrays: Mathematical test arrays
  • original_cwd: Working directory preservation
  • File operation helpers

Validation Results

18/18 validation tests pass

  • Basic pytest functionality
  • Fixture availability and functionality
  • Custom marker system
  • Mock and coverage integration
  • File operations and cleanup
  • Environment configuration

Usage Instructions

Installation

poetry install

Running Tests

# All tests
poetry run pytest

# With verbose output
poetry run pytest -v

# Specific test file
poetry run pytest tests/test_setup_validation.py

# By markers
poetry run pytest -m unit
poetry run pytest -m "not slow"

Coverage Analysis

# Generate coverage report
poetry run pytest --cov=scripts --cov-report=html

# View HTML report
open htmlcov/index.html

Next Steps

This infrastructure is now ready for developers to:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use provided fixtures for common testing scenarios
  4. Leverage coverage reporting for code quality
  5. Integrate with CI/CD pipelines

The testing framework is specifically configured for the VIO trajectory processing and evaluation functionality in the existing scripts.

Notes

  • Poetry Lock File: The poetry.lock file is included for reproducible dependency versions
  • Python Version: Requires Python 3.8+ as specified in pyproject.toml
  • Coverage Threshold: Set to 80% - can be adjusted in pyproject.toml if needed
  • Extensibility: Framework easily supports additional test types and fixtures

🤖 Generated with Claude Code

- Add Poetry package management with pyproject.toml configuration
- Install pytest, pytest-cov, and pytest-mock testing dependencies
- Create complete testing directory structure (tests/unit/, tests/integration/)
- Configure pytest with coverage reporting, custom markers, and strict options
- Add comprehensive shared fixtures in tests/conftest.py
- Set up .gitignore with testing and development entries
- Create validation test suite to verify infrastructure functionality
- Configure 80% coverage threshold with HTML/XML reporting

🤖 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