batch-ppo
batch-ppo 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 batch-ppo project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and maintaining tests with proper coverage reporting and development tooling.
Changes Made
Package Management
- ✅ Added Poetry configuration in
pyproject.toml - ✅ Migrated existing dependencies from
setup.py - ✅ Added development dependencies for testing
Testing Configuration
- ✅ Configured pytest with:
- Test discovery patterns for
test_*.pyand*_test.py - Coverage reporting with 80% threshold
- HTML and XML coverage output formats
- Custom test markers:
@pytest.mark.unit,@pytest.mark.integration,@pytest.mark.slow - Strict marker enforcement
- Test discovery patterns for
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_setup_validation.py # Infrastructure validation
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (in conftest.py)
temp_dir: Temporary directory with automatic cleanupmock_config: Sample configuration dictionarymock_config_file: Temporary YAML config filetf_session: TensorFlow session managementmock_environment: Mock Gym environmentsample_trajectory: Sample training datacleanup_tensorflow: Automatic TF state cleanupcapture_stdout: Stdout capture for testing print statements
Development Commands
Both commands are configured to run the test suite:
poetry run testpoetry run tests
Additional Updates
- Updated
.gitignorewith:- Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
- Claude settings (.claude/*)
- Virtual environments and IDE files
- Note: poetry.lock is NOT ignored (should be committed)
How to Use
-
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 - -
Install dependencies:
poetry install -
Run tests:
poetry run test # or poetry run tests -
Run specific test categories:
# Unit tests only poetry run pytest -m unit # Integration tests only poetry run pytest -m integration # Exclude slow tests poetry run pytest -m "not slow" -
View coverage report:
- Terminal: Automatically shown after test run
- HTML: Open
htmlcov/index.htmlin browser - XML: Available at
coverage.xmlfor CI integration
Notes
- The validation test suite confirms all infrastructure components are working correctly
- Coverage threshold is set to 80% - tests will fail if coverage drops below this
- The codebase has TensorFlow 1.x compatibility issues that need to be addressed separately
- All pytest options remain available (e.g.,
-vfor verbose,-xto stop on first failure)
Next Steps
With this infrastructure in place, developers can now:
- Write unit tests in
tests/unit/ - Write integration tests in
tests/integration/ - Use the provided fixtures for common testing needs
- Monitor test coverage to maintain code quality