Skip to content

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 20, 2025

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_*.py and *_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

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 cleanup
  • mock_config: Sample configuration dictionary
  • mock_config_file: Temporary YAML config file
  • tf_session: TensorFlow session management
  • mock_environment: Mock Gym environment
  • sample_trajectory: Sample training data
  • cleanup_tensorflow: Automatic TF state cleanup
  • capture_stdout: Stdout capture for testing print statements

Development Commands

Both commands are configured to run the test suite:

  • poetry run test
  • poetry run tests

Additional Updates

  • Updated .gitignore with:
    • 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

  1. Install Poetry (if not already installed):

    curl -sSL https://install.python-poetry.org | python3 -
  2. Install dependencies:

    poetry install
  3. Run tests:

    poetry run test
    # or
    poetry run tests
  4. 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"
  5. View coverage report:

    • Terminal: Automatically shown after test run
    • HTML: Open htmlcov/index.html in browser
    • XML: Available at coverage.xml for 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., -v for verbose, -x to stop on first failure)

Next Steps

With this infrastructure in place, developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures for common testing needs
  4. Monitor test coverage to maintain code quality

- Add Poetry package manager configuration with pyproject.toml
- Configure pytest with coverage reporting (80% threshold)
- Create testing directory structure (unit/integration)
- Add development dependencies: pytest, pytest-cov, pytest-mock
- Configure custom test markers (unit, integration, slow)
- Set up shared fixtures in conftest.py
- Update .gitignore with testing and Claude entries
- Add validation tests to verify infrastructure
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