Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 17, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the BlendArMocap project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and running tests, with proper organization, fixtures, and coverage reporting.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with complete project metadata and dependency management
  • Dependency Migration: Migrated existing dependencies from requirements.txt to Poetry
  • Optional Dependencies: Made mediapipe optional to handle platform compatibility issues

Testing Framework

  • pytest: Added as the main testing framework with version 8.0.0+
  • pytest-cov: Added for coverage reporting with HTML and XML output
  • pytest-mock: Added for mocking utilities in tests

Testing Configuration

  • Test Discovery: Configured to find tests in the tests/ directory
  • Coverage Settings: Set up with source tracking, branch coverage, and reporting
  • Custom Markers: Added unit, integration, and slow markers for test categorization
  • Warning Filters: Configured to ignore deprecation warnings and coverage warnings

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures and configuration
├── unit/                # Unit tests
│   ├── __init__.py
│   └── test_setup_validation.py
└── integration/         # Integration tests
    └── __init__.py

Fixtures (in conftest.py)

  • temp_dir: Temporary directory creation and cleanup
  • temp_file: Temporary file creation
  • mock_config: Mock configuration dictionary
  • mock_json_file: Mock JSON file creation
  • mock_logger: Mock logger object
  • mock_blender_context: Mock Blender context for add-on testing
  • mock_blender_operator: Mock Blender operator
  • sample_mediapipe_data: Sample MediaPipe pose data
  • mock_opencv_image: Mock OpenCV image array
  • cleanup_files: File cleanup tracking
  • capture_stdout: Stdout capture for testing print statements

Development Tools

  • black: Code formatter with 88-character line length
  • isort: Import sorting configured to work with black
  • flake8: Linting tool for code quality
  • mypy: Type checking with basic configuration

Commands

Both commands work identically to run tests:

  • poetry run test
  • poetry run tests

Usage Instructions

Initial Setup

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

# Install project dependencies
poetry install

# Install with mediapipe (optional, may have compatibility issues)
poetry install -E mediapipe

Running Tests

# Run all tests with coverage
poetry run test

# Run tests without coverage
poetry run pytest --no-cov

# Run only unit tests
poetry run pytest -m unit

# Run tests with verbose output
poetry run pytest -v

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

Coverage Reports

After running tests, coverage reports are available in:

  • Terminal: Shows summary with missing lines
  • HTML: Open htmlcov/index.html in a browser
  • XML: coverage.xml for CI integration

Notes

  1. Python Version: Set to Python 3.9+ due to flake8 requirements
  2. MediaPipe: Made optional due to platform compatibility issues
  3. Coverage Threshold: Currently set to 0% to allow initial setup without failing
  4. Blender Integration: Tests that require Blender will be automatically skipped when not in Blender environment

Validation

The setup includes validation tests that verify:

  • All testing dependencies are properly installed
  • Fixtures are available and working
  • Project structure is correct
  • Configuration is properly set up
  • Both test commands work as expected

All validation tests are passing, confirming the testing infrastructure is ready for use.

- Set up Poetry as package manager with pyproject.toml configuration
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Configure pytest with markers (unit, integration, slow) and coverage settings
- Create organized test directory structure (tests/unit, tests/integration)
- Add comprehensive conftest.py with common fixtures for testing
- Update .gitignore with testing and Poetry-related entries
- Add validation tests to verify the testing setup works correctly
- Configure both 'poetry run test' and 'poetry run tests' commands
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