Skip to content

feat: Add comprehensive Python testing infrastructure with Poetry #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 16, 2025

Add Python Testing Infrastructure to RenderPipeline

Summary

This PR establishes a comprehensive testing infrastructure for the RenderPipeline project using modern Python tooling. The setup enables developers to immediately start writing tests with proper dependency management, test discovery, and coverage reporting.

Changes Made

Package Management

  • Poetry Configuration: Added pyproject.toml with Poetry setup in package-mode=false (dependency management only)
  • Dependencies Migrated: Identified and migrated core dependencies (Panda3D, PyYAML, colorama, progressbar2, six)
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies
  • Optional GUI Dependencies: PyQt5 configured as optional dependency group

Testing Configuration

  • pytest Configuration:

    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting with HTML, XML, and terminal output
    • Custom markers: unit, integration, slow
    • Strict mode enabled for better error detection
  • Coverage Settings:

    • Source paths: rpcore, rpplugins, rplibs
    • Excluded: test files, samples, toolkit, cache directories
    • Multiple report formats (HTML, XML, terminal)
    • Currently set to 0% threshold (should be adjusted as tests are added)

Test Infrastructure

  • Directory Structure:

    tests/
    ├── __init__.py
    ├── conftest.py          # Shared fixtures and configuration
    ├── unit/                # Unit tests directory
    │   └── __init__.py
    ├── integration/         # Integration tests directory
    │   └── __init__.py
    └── test_setup_validation.py  # Infrastructure validation tests
    
  • Shared Fixtures (in conftest.py):

    • temp_dir: Temporary directory management
    • mock_panda3d: Mock Panda3D modules for testing without installation
    • sample_config: Sample configuration dictionaries
    • config_file: Temporary YAML config files
    • mock_render_pipeline: Mock RenderPipeline instance
    • mock_light, mock_plugin, mock_texture: Common mock objects
    • sample_shader_code: Sample GLSL shader code
    • capture_logs: Log capture utility
    • Auto-setup of test environment with proper Python paths

Additional Updates

  • .gitignore Updates: Added patterns for:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
    • Poetry/package management files
    • Virtual environments
    • IDE files
    • Claude settings (.claude/*)

How to Use

Installation

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

# Install dependencies
poetry install

# Install optional GUI dependencies
poetry install --with gui

Running Tests

# Run all tests
poetry run pytest

# Run with verbose output
poetry run pytest -v

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

# Run tests by marker
poetry run pytest -m unit
poetry run pytest -m "not slow"

# Run with coverage report
poetry run pytest --cov-report=html
# Then open htmlcov/index.html in a browser

Writing Tests

  1. Create test files in tests/unit/ or tests/integration/
  2. Use the provided fixtures from conftest.py
  3. Mark tests appropriately:
    @pytest.mark.unit
    def test_something():
        pass
    
    @pytest.mark.integration
    @pytest.mark.slow
    def test_complex_integration():
        pass

Notes

  • The project uses bundled dependencies in rplibs/, which are included in the coverage reports
  • Coverage threshold is currently set to 0% to allow infrastructure setup; this should be increased as tests are added
  • The yaml_py2 modules show parsing warnings due to Python 2 syntax but don't affect functionality
  • Poetry is configured in non-package mode since RenderPipeline isn't distributed as a package

Future Improvements

  • Increase coverage threshold as more tests are added
  • Add pre-commit hooks for running tests
  • Consider adding tox for testing across multiple Python versions
  • Add CI/CD integration for automated testing

- Set up Poetry for modern dependency management (package-mode=false)
- Add pytest with coverage, mock support, and custom markers
- Configure test discovery, coverage thresholds, and reporting
- Create organized test structure with unit/integration directories
- Add comprehensive pytest fixtures for common testing scenarios
- Update .gitignore with testing and Poetry-related patterns
- Create validation tests to verify infrastructure setup
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