Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 27, 2025

Add Comprehensive Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the project using Poetry as the package manager and pytest as the testing framework. The setup provides a ready-to-use environment for developers to immediately start writing tests.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Dependency Migration: Migrated all dependencies from requirements.txt to Poetry
  • Flexible Versioning: Used caret (^) version constraints for better compatibility
  • Development Dependencies: Added pytest, pytest-cov, pytest-mock, and supporting tools

Testing Configuration

  • pytest Configuration: Comprehensive pytest settings in pyproject.toml including:
    • Coverage threshold set to 80%
    • Multiple coverage report formats (HTML, XML, terminal)
    • Custom markers for unit, integration, and slow tests
    • Strict mode enabled for better test quality
    • Test discovery patterns configured

Directory Structure

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

Shared Fixtures (conftest.py)

Created comprehensive fixtures for common testing needs:

  • File handling: temp_dir, sample_yaml_config, sample_json_config, sample_h5_data
  • Data fixtures: sample_numpy_array, sample_torch_tensor, sample_config
  • Mock objects: mock_model, mock_dataset, mock_dynamixel_driver, mock_websocket
  • Environment: env_vars for temporary environment variable management
  • Project-specific: mock_robot_state, sample_episode_data, mock_camera_image
  • Utilities: Automatic random seed reset, wandb mocking

Additional Setup

  • Updated .gitignore: Added entries for testing artifacts, Poetry files, and development tools
  • Validation Tests: Created comprehensive tests to verify the infrastructure works correctly
  • Poetry Scripts: Configured both poetry run test and poetry run tests commands

Usage Instructions

Running Tests

# Using Poetry (after installation)
poetry run test
poetry run tests

# Running specific test types
poetry run pytest -m unit        # Run only unit tests
poetry run pytest -m integration # Run only integration tests
poetry run pytest --runslow      # Include slow tests

# Using pytest directly
pytest
pytest -v                        # Verbose output
pytest --cov                     # With coverage report
pytest tests/unit/               # Run only unit tests directory

Writing Tests

  1. Place unit tests in tests/unit/
  2. Place integration tests in tests/integration/
  3. Use fixtures from conftest.py for common test needs
  4. Mark tests appropriately:
    @pytest.mark.unit
    def test_example():
        pass
    
    @pytest.mark.integration
    def test_integration():
        pass
    
    @pytest.mark.slow
    def test_slow_operation():
        pass

Coverage Reports

  • HTML report: htmlcov/index.html
  • XML report: coverage.xml
  • Terminal report: Shown after test run

Notes

  • The dex-retargeting package was commented out due to Python version constraints (requires Python <3.11)
  • Poetry installation might take time due to large dependencies (torch, torchvision)
  • All test infrastructure has been validated with passing tests

Next Steps

Developers can now:

  1. Install dependencies with poetry install
  2. Start writing unit and integration tests
  3. Use the provided fixtures for faster test development
  4. Monitor coverage to maintain the 80% threshold

- Set up Poetry as package manager with flexible dependency versions
- Add pytest, pytest-cov, and pytest-mock for testing
- Configure pytest with coverage thresholds (80%) and custom markers
- Create organized test directory structure (unit/integration)
- Add comprehensive conftest.py with reusable fixtures
- Update .gitignore with testing and Poetry-related entries
- Add validation tests to verify infrastructure 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