visual-pushing-grasping
visual-pushing-grasping copied to clipboard
feat: Set up comprehensive Python testing infrastructure with Poetry
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.tomlwith 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.lockfor reproducible installations
Testing Configuration
-
pytest Configuration in
pyproject.toml:- Strict markers and configuration enforcement
- Test discovery patterns for
test_*.pyand*_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 managementmock_config: Configuration object for testingsample_rgb_image,sample_depth_image: Test image datamock_robot,mock_trainer,mock_logger: Mocked componentsvrep_connection: Mock V-REP simulation connectionsample_workspace_limits: Robot workspace boundariessample_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
- Create test files in
tests/unit/ortests/integration/ - Use fixtures from
conftest.pyfor common test needs - Mark tests appropriately:
@pytest.mark.unit,@pytest.mark.integration,@pytest.mark.slow - 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 testandpoetry run testscommands are available for developer preference - The testing infrastructure is ready for immediate use - developers can start writing unit and integration tests right away