Skip to content

feat: Add complete Python testing infrastructure with Poetry#27

Open
llbbl wants to merge 1 commit intoHTDerekLiu:masterfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Add complete Python testing infrastructure with Poetry#27
llbbl wants to merge 1 commit intoHTDerekLiu:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 29, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the BlenderToolbox project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Migration: Migrated existing project metadata from setup.py to Poetry
  • Dependencies: Added testing dependencies as development requirements:
    • pytest (^8.0.0) - Main testing framework
    • pytest-cov (^5.0.0) - Coverage reporting
    • pytest-mock (^3.14.0) - Mocking utilities

Testing Configuration

  • Pytest Configuration: Added comprehensive pytest settings in pyproject.toml:

    • Test discovery patterns for flexible test file naming
    • Coverage settings with 80% threshold requirement
    • HTML and XML coverage report generation
    • Custom markers: unit, integration, slow
    • Strict mode enabled for better error detection
  • Coverage Configuration: Set up coverage.py with:

    • Source directory specification
    • Exclusion patterns for test files and virtual environments
    • Detailed reporting options

Directory Structure

tests/
├── __init__.py
├── conftest.py
├── test_setup_validation.py
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures (conftest.py)

Created comprehensive fixtures for common testing needs:

  • temp_dir: Temporary directory management
  • mock_blend_file, mock_obj_file, mock_ply_file, mock_stl_file: Mock 3D file formats
  • mock_image_file: Mock image files
  • mock_numpy_data: Mock numpy arrays (with fallback for when numpy isn't installed)
  • mock_config: Sample configuration data
  • isolate_environment: Environment isolation for tests
  • capture_logs: Log capturing during tests

Development Workflow

  • Poetry Scripts: Added both test and tests commands that map to pytest
  • Updated .gitignore: Added entries for:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
    • Claude settings (.claude/*)
    • Virtual environments
    • IDE files
    • Poetry artifacts (with note to keep poetry.lock)

Additional Notes

  • Numpy: Added as an optional dependency to support projects that may use it
  • Python Version: Supports Python 3.10+
  • Validation Test: Included test_setup_validation.py to verify the infrastructure works correctly

How to Use

Installation

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

# Install project dependencies
poetry install

Running Tests

# Run all tests
poetry run test

# Alternative command (both work)
poetry run tests

# Run with specific options
poetry run pytest -v                    # Verbose output
poetry run pytest tests/unit/           # Run only unit tests
poetry run pytest -m integration        # Run only integration tests
poetry run pytest --cov-report=html     # Generate HTML coverage report

Writing Tests

  1. Place unit tests in tests/unit/
  2. Place integration tests in tests/integration/
  3. Use fixtures from conftest.py for common test needs
  4. Mark tests appropriately:
    @pytest.mark.unit
    def test_something():
        pass
    
    @pytest.mark.integration
    def test_integration():
        pass
    
    @pytest.mark.slow
    def test_slow_operation():
        pass

Next Steps

With this infrastructure in place, developers can immediately start writing tests for the BlenderToolbox functionality. The validation test (test_setup_validation.py) demonstrates how to use the fixtures and confirms the setup is working correctly.

- Set up Poetry as package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting (80% threshold)
- Create test directory structure with unit/integration folders
- Add comprehensive conftest.py with reusable fixtures
- Update .gitignore with testing and development entries
- Add Poetry scripts for running tests (test/tests commands)
- Include 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