Skip to content

Conversation

llbbl
Copy link

@llbbl llbbl commented Sep 3, 2025

Set up Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the Extra Image List Blender addon, providing a complete development environment for writing and running tests.

Changes Made

Package Management

  • Poetry Setup: Added pyproject.toml with Poetry configuration for dependency management
  • Testing Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies
  • Package Mode: Configured as library mode since this is a Blender addon, not a standalone package

Testing Configuration

  • Pytest Configuration: Comprehensive pytest settings in pyproject.toml including:
    • Test discovery patterns for test_*.py and *_test.py files
    • Strict configuration for markers and config validation
    • Custom markers: unit, integration, and slow
    • Verbose output by default

Coverage Reporting

  • Coverage Settings: Configured with 80% coverage threshold
  • Multiple Report Formats: HTML (htmlcov/), XML (coverage.xml), and terminal output
  • Smart Exclusions: Excludes test files, virtual environments, build artifacts, and the main Blender module

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures and test configuration
├── unit/                # Fast, isolated unit tests
│   └── __init__.py
├── integration/         # Slower tests with dependencies
│   └── __init__.py
└── test_setup_validation.py  # Validation tests for the infrastructure

Shared Fixtures (conftest.py)

  • Temporary File System: temp_dir and temp_file fixtures for test isolation
  • Blender Mocking: Comprehensive mocks for bpy module and Blender contexts
  • Test Data: Sample image lists, configurations, and operator mocks
  • Environment Management: Automatic environment cleanup and isolation

Development Workflow

  • Run All Tests: poetry run pytest
  • Run with Coverage: poetry run pytest --cov
  • Run Unit Tests Only: poetry run pytest -m "unit"
  • Run Without Slow Tests: poetry run pytest -m "not slow"
  • Generate HTML Coverage Report: Coverage reports automatically generated in htmlcov/

Git Integration

  • Updated .gitignore: Added entries for testing artifacts, coverage reports, virtual environments, and Claude settings
  • Preserved Lock Files: Poetry lock files are tracked for reproducible builds

Testing Infrastructure Validation

The setup includes a comprehensive validation test suite (test_setup_validation.py) that verifies:

Basic pytest functionality (assertions, parametrized tests)
All fixtures work correctly (temp files, Blender mocks, test data)
Mocking capabilities (unittest.mock, patches, MagicMock)
Test markers function (unit, integration, slow)
Coverage reporting (branch coverage, exclusions)
Error handling (exception testing, message validation)
Data-driven testing (parametrized test cases)

Test Results: 31 tests pass, demonstrating that all infrastructure components are working correctly.

Usage Instructions

Initial Setup

# Install dependencies
poetry install --no-root

# Run all tests
poetry run pytest

# Run tests with coverage
poetry run pytest --cov

# Run specific test types
poetry run pytest -m "unit"        # Unit tests only
poetry run pytest -m "integration" # Integration tests only  
poetry run pytest -m "not slow"    # Exclude slow tests

Coverage Reports

  • Terminal: Coverage summary shown after test run
  • HTML Report: Open htmlcov/index.html in browser for detailed coverage
  • XML Report: coverage.xml for CI/CD integration

Writing Tests

  • Unit tests: Place in tests/unit/ for fast, isolated tests
  • Integration tests: Place in tests/integration/ for tests with dependencies
  • Use fixtures: Leverage shared fixtures from conftest.py for common test data
  • Mark slow tests: Use @pytest.mark.slow for tests that take significant time

Notes

  • Blender Compatibility: The testing infrastructure is designed specifically for Blender addons with comprehensive bpy module mocking
  • No Production Dependencies: All testing dependencies are in the [tool.poetry.group.test] section
  • Ready for CI/CD: Configuration supports automated testing with coverage reporting in standard formats
  • Extensible: Easy to add new fixtures, markers, and test utilities as the project grows

🤖 Generated with Claude Code

- Add Poetry package manager with pyproject.toml configuration
- Configure pytest with coverage reporting, custom markers, and strict options
- Set up testing directory structure with unit/integration separation
- Create comprehensive shared fixtures for Blender addon testing
- Add validation tests to verify testing infrastructure functionality
- Configure .gitignore for testing artifacts and development files
- Support 80% test coverage threshold with HTML/XML reporting

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
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