Skip to content

feat: Set up comprehensive Python testing infrastructure with Poetry#99

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

feat: Set up comprehensive Python testing infrastructure with Poetry#99
llbbl wants to merge 1 commit intoandyzeng:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Jun 14, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the visual-pushing-grasping project, migrating from manual dependency management to Poetry and setting up pytest with all necessary tooling for effective test development.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Dependency Migration: Migrated existing dependencies from README.md:
    • Core: numpy, scipy, opencv-python, matplotlib, torch, torchvision
    • Development: pytest, pytest-cov, pytest-mock
  • Lock File: Generated poetry.lock for reproducible installations

Testing Configuration

  • pytest Configuration in pyproject.toml:

    • Strict markers and configuration enforcement
    • Test discovery patterns for test_*.py and *_test.py
    • Custom markers: unit, integration, slow
    • Verbose output with detailed failure reporting
  • Coverage Configuration:

    • 80% coverage threshold requirement
    • HTML and XML report generation
    • Exclusions for common patterns (tests, cache, virtual environments)
    • Branch coverage tracking

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures
├── test_setup_validation.py  # Infrastructure validation
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory management
  • mock_config: Configuration object for testing
  • sample_rgb_image, sample_depth_image: Test image data
  • mock_robot, mock_trainer, mock_logger: Mocked components
  • vrep_connection: Mock V-REP simulation connection
  • sample_workspace_limits: Robot workspace boundaries
  • sample_torch_model: Simple PyTorch model for testing
  • Auto-reset random seeds for reproducibility

Additional Updates

  • Updated .gitignore with:
    • Testing artifacts (.pytest_cache, .coverage, htmlcov/)
    • Claude settings (.claude/*)
    • Virtual environments and IDE files
    • Build artifacts and Python cache

Usage Instructions

Installation

# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -

# Install dependencies
poetry install

Running Tests

# Run all tests
poetry run test
# or
poetry run tests

# Run with coverage
poetry run pytest --cov=real --cov=simulation --cov-report=html

# Run specific test markers
poetry run pytest -m unit
poetry run pytest -m "not slow"

# Run specific test file
poetry run pytest tests/test_setup_validation.py

Writing Tests

  1. Create test files in tests/unit/ or tests/integration/
  2. Use fixtures from conftest.py for common test needs
  3. Mark tests appropriately: @pytest.mark.unit, @pytest.mark.integration, @pytest.mark.slow
  4. Follow the validation test examples for guidance

Validation

The infrastructure has been validated with 17 passing tests that verify:

  • Framework installation and configuration
  • Fixture accessibility and functionality
  • Test markers and parametrization
  • Mock objects and test utilities
  • Coverage exclusion patterns

Notes

  • Poetry is configured to use Python 3.8+ to match the project's existing Python version requirements
  • The coverage threshold is set to 80% but currently only applies when testing actual source code (not the validation tests)
  • Both poetry run test and poetry run tests commands are available for developer preference
  • The testing infrastructure is ready for immediate use - developers can start writing unit and integration tests right away

- Migrate to Poetry for dependency management with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Configure pytest with coverage reporting, custom markers, and test discovery
- Create testing directory structure with unit/integration subdirectories
- Add comprehensive shared fixtures in conftest.py for mocking and testing
- Update .gitignore with testing artifacts and Claude settings
- Include validation tests to verify infrastructure functionality
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