Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 3, 2025

Add Complete Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the robot arm teleoperation and ACT (Action Chunking with Transformers) project. The infrastructure provides everything needed for developers to immediately start writing and running tests.

Changes Made

Package Management

  • Set up Poetry as the package manager with pyproject.toml
  • Migrated dependencies from requirements.txt to Poetry format
  • Organized dependencies into main dependencies and test group dependencies

Testing Framework

  • Added pytest as the main testing framework with comprehensive configuration
  • Added pytest-cov for coverage reporting (HTML, XML, terminal)
  • Added pytest-mock for advanced mocking capabilities
  • Configured 80% coverage threshold to maintain code quality

Test Organization

  • Created test directory structure:
    tests/
    ├── __init__.py
    ├── conftest.py          # Shared fixtures
    ├── unit/
    │   └── __init__.py
    ├── integration/
    │   └── __init__.py
    └── test_infrastructure_validation.py
    

Test Configuration

  • Custom pytest markers: unit, integration, slow
  • Coverage settings: Source tracking for act/ and server/ packages
  • Test discovery: Automatic discovery of test files and classes
  • Report formats: Terminal, HTML (htmlcov/), and XML (coverage.xml)

Shared Test Fixtures

Created comprehensive fixtures in conftest.py:

  • 🔧 File system: temp_dir, temp_file
  • ⚙️ Configuration: sample_config
  • 🤖 Robot mocks: mock_serial_connection, mock_dynamixel_handler
  • 📷 Camera mocks: mock_camera with sample image data
  • 🌐 Network mocks: mock_tcp_socket, mock_udp_socket
  • 📊 Data mocks: sample_trajectory_data, sample_hdf5_dataset
  • 🧠 ML mocks: mock_torch_model, mock_mujoco_env

Development Environment

  • Updated .gitignore with testing artifacts and development files
  • Added Claude Code settings to .gitignore for better developer experience
  • IDE and build artifacts properly ignored

Running Tests

Basic Usage

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov=act --cov=server

# Run without coverage (faster)
poetry run pytest --no-cov

# Run only unit tests
poetry run pytest -m unit

# Run only integration tests  
poetry run pytest -m integration

# Run with verbose output
poetry run pytest -v

Coverage Reports

  • Terminal: Shows coverage summary after test run
  • HTML: Open htmlcov/index.html in browser for detailed coverage report
  • XML: coverage.xml for CI/CD integration

Test Organization

  • Unit tests: Place in tests/unit/ for isolated component testing
  • Integration tests: Place in tests/integration/ for multi-component testing
  • Mark slow tests: Use @pytest.mark.slow for tests that take significant time

Installation

The testing infrastructure is ready to use:

# Install all dependencies including testing
poetry install

# Install only test dependencies
poetry install --only test

Validation

The setup includes comprehensive validation tests that verify:

  • ✅ Python version compatibility
  • ✅ pytest configuration and markers
  • ✅ All fixtures are working correctly
  • ✅ Project structure is properly recognized
  • ✅ Coverage reporting functions
  • ✅ Mock dependencies are available

Run validation: poetry run pytest tests/test_infrastructure_validation.py

Next Steps

With this infrastructure in place, developers can:

  1. Start writing tests immediately using the provided fixtures
  2. Run tests with confidence knowing coverage is tracked
  3. Use pre-configured mocks for robot, camera, and network components
  4. Follow testing best practices with organized test structure
  5. Integrate with CI/CD using coverage XML reports

The infrastructure supports the full development lifecycle from local testing to continuous integration.


🤖 Generated with Claude Code

- Set up Poetry package manager with pyproject.toml
- Migrate dependencies from requirements.txt to Poetry format
- Add pytest, pytest-cov, and pytest-mock testing dependencies
- Configure pytest with coverage reporting and custom markers (unit, integration, slow)
- Create complete tests/ directory structure with unit/ and integration/ subdirs
- Add comprehensive conftest.py with shared fixtures for mocking and test data
- Update .gitignore with testing artifacts and development files
- Create validation tests to verify testing infrastructure works correctly
- Configure 80% coverage threshold with HTML and XML reporting
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