Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 4, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the TRANSIC project using Poetry and pytest. The setup provides a complete foundation for writing and running tests with proper coverage reporting and CI/CD integration capabilities.

Key Changes Made:

  • Package Management: Configured Poetry as the package manager with pyproject.toml
  • Dependency Migration: Migrated all dependencies from requirements.txt and setup.py to Poetry format
  • Testing Framework: Added pytest with coverage reporting (pytest-cov) and mocking utilities (pytest-mock)
  • Test Configuration: Comprehensive pytest configuration with custom markers and 80% coverage threshold
  • Directory Structure: Created organized tests/ directory with unit/ and integration/ subdirectories
  • Shared Fixtures: Extensive set of reusable fixtures in conftest.py for common testing scenarios
  • Coverage Reporting: HTML and XML coverage reports with configurable exclusions
  • CI/CD Ready: All necessary configuration for automated testing workflows

Testing Infrastructure Components Added

Configuration Files

  • pyproject.toml - Complete Poetry and pytest configuration
  • Updated .gitignore - Testing artifacts and coverage reports excluded

Directory Structure

tests/
├── __init__.py
├── conftest.py           # Shared fixtures and test configuration
├── unit/                 # Unit tests directory
│   └── __init__.py
├── integration/          # Integration tests directory  
│   └── __init__.py
└── test_infrastructure_validation.py  # Validation tests

Test Markers

  • @pytest.mark.unit - For unit tests
  • @pytest.mark.integration - For integration tests
  • @pytest.mark.slow - For slow-running tests

Shared Fixtures Available

  • temp_dir, temp_file - Temporary file system fixtures
  • mock_config, sample_config_dict - Configuration mocking
  • sample_tensor, sample_numpy_array - Data fixtures for ML testing
  • mock_env, mock_policy - RL environment and policy mocking
  • mock_dataset, mock_dataloader - Data loading fixtures
  • sample_pointcloud, sample_trajectory - Domain-specific test data
  • mock_lightning_module - PyTorch Lightning testing support

Running Tests

Basic Commands

# Install dependencies
poetry install

# Run all tests
poetry run pytest

# Run with verbose output
poetry run pytest -v

# Run only unit tests
poetry run pytest -m "unit"

# Run excluding slow tests
poetry run pytest -m "not slow"

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

Coverage Reports

  • Terminal: Coverage summary displayed after test run
  • HTML: Detailed coverage report in htmlcov/ directory
  • XML: Machine-readable report in coverage.xml

Dependencies and Compatibility

Key Dependencies Added

  • pytest ^7.4.0 - Main testing framework
  • pytest-cov ^4.1.0 - Coverage reporting
  • pytest-mock ^3.11.1 - Enhanced mocking capabilities

Python Version Compatibility

  • Supports Python >=3.8,<4.0
  • Special handling for rl-games dependency (requires Python <3.11)

Validation

All tests pass successfully:

  • ✅ 13 validation tests confirm infrastructure is working
  • ✅ All fixtures and markers functioning correctly
  • ✅ Coverage reporting operational
  • ✅ Test discovery and execution working
  • ✅ Mock dependencies properly configured

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use shared fixtures from conftest.py
  4. Run tests locally with poetry run pytest
  5. Generate coverage reports to identify untested code
  6. Set up CI/CD workflows using the pytest configuration

🤖 Generated with Claude Code

- Configure Poetry as package manager with pyproject.toml
- Migrate dependencies from requirements.txt and setup.py
- Add pytest, pytest-cov, pytest-mock as test dependencies
- Create testing configuration with 80% coverage threshold
- Set up tests/ directory structure with unit/integration subdirs
- Add comprehensive shared fixtures in conftest.py
- Configure test markers (unit, integration, slow)
- Update .gitignore with testing and coverage entries
- Add validation tests to verify infrastructure setup

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

Co-Authored-By: Claude <[email protected]>
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