Skip to content

feat: Set up complete Python testing infrastructure with Poetry - #35

Open
llbbl wants to merge 1 commit into
blackbox114:masterfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up complete Python testing infrastructure with Poetry#35
llbbl wants to merge 1 commit into
blackbox114:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl

@llbbl llbbl commented Sep 1, 2025

Copy link
Copy Markdown

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the Blacky quadruped robot project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry setup for dependency management
  • Dependencies: Migrated existing dependencies (numpy, pigpio, transforms3d, pyserial, matplotlib) to Poetry format
  • Development Dependencies: Added testing-specific packages:
    • pytest (v7.4.0+) - Main testing framework
    • pytest-cov (v4.1.0+) - Coverage reporting
    • pytest-mock (v3.11.0+) - Mocking utilities

Testing Configuration

  • pytest Configuration: Comprehensive setup in pyproject.toml including:
    • Test discovery patterns (test_*.py, *_test.py)
    • Coverage settings with 80% threshold
    • Custom markers: unit, integration, slow
    • Strict configuration options
    • Multiple coverage report formats (terminal, HTML, XML)

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures
├── unit/
│   └── __init__.py
├── integration/
│   └── __init__.py
└── test_infrastructure_validation.py

Shared Testing Utilities

  • conftest.py: Comprehensive fixture library including:
    • Hardware mocks (mock_hardware_interface, mock_imu, mock_joystick)
    • Configuration mocks (mock_config, mock_state)
    • Utility fixtures (temp_dir, numpy_arrays_equal)
    • Sample data fixtures (sample_joint_angles, sample_foot_positions)
    • Automatic pigpio mocking for hardware-free testing

Validation & Quality Assurance

  • Infrastructure Tests: Created validation test suite to verify:
    • Python version compatibility (3.8+)
    • All dependencies properly installed and importable
    • Pytest configuration working correctly
    • Fixtures available and functional
    • Coverage measurement operational
    • Mocking functionality working

Project Maintenance

  • Updated .gitignore: Added entries for:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/)
    • Claude Code settings (.claude/)
    • IDE files and OS-specific files

How to Use

Running Tests

# Run all tests
poetry run pytest

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

# Run only unit tests
poetry run pytest -m unit

# Run only integration tests
poetry run pytest -m integration

# Skip slow tests
poetry run pytest -m "not slow"

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

Installing Dependencies

# Install all dependencies
poetry install

# Install only production dependencies
poetry install --only main

Test Development

  • Place unit tests in tests/unit/
  • Place integration tests in tests/integration/
  • Use fixtures from conftest.py for consistent test setup
  • Follow naming conventions: test_*.py or *_test.py

Validation Results

✅ All infrastructure validation tests pass (16/16)
✅ Dependencies successfully installed
✅ Coverage reporting functional (HTML and XML output)
✅ Custom markers working correctly
✅ Mock fixtures operational

Notes

  • UDPComms Dependency: Removed UDPComms from dependencies as it's not available in PyPI. This will need to be addressed separately if it's a required custom package.
  • Coverage Threshold: Set to 80% - currently failing as expected since no unit tests exist yet
  • Python Compatibility: Configured for Python 3.8+ to maintain broad compatibility
  • Poetry Scripts: Removed custom script shortcuts due to Poetry format requirements. Use poetry run pytest directly.

Next Steps

  1. Begin writing unit tests for individual modules
  2. Add integration tests for robot control workflows
  3. Address the UDPComms dependency if needed
  4. Consider adding pre-commit hooks for automated testing
  5. Set up CI/CD pipeline to run tests automatically

Testing Infrastructure Ready ✅

The project now has a complete, production-ready testing infrastructure. Developers can immediately start writing tests using the provided fixtures and utilities.

- Add Poetry package manager configuration in pyproject.toml
- Configure pytest with coverage reporting, custom markers, and test discovery
- Create comprehensive testing directory structure (tests/, unit/, integration/)
- Add shared pytest fixtures in conftest.py for robot components
- Set up coverage thresholds (80%) with HTML and XML reporting
- Update .gitignore with testing and IDE-related entries
- Create validation tests to verify infrastructure functionality
- Install testing dependencies: pytest, pytest-cov, pytest-mock
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