Skip to content

Set up comprehensive Python testing infrastructure with Poetry#21

Open
llbbl wants to merge 1 commit into3DTopia:mainfrom
UnitSeeker:add-testing-infrastructure
Open

Set up comprehensive Python testing infrastructure with Poetry#21
llbbl wants to merge 1 commit into3DTopia:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Jun 23, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the DVA-MVP Python project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Created pyproject.toml with Poetry configuration
  • Migrated all dependencies from requirements.txt to Poetry
  • Added testing dependencies as development dependencies:
    • pytest (^8.0.0) - Main testing framework
    • pytest-cov (^5.0.0) - Coverage reporting
    • pytest-mock (^3.14.0) - Mocking utilities
    • pillow (^10.0.0) - Image handling for test fixtures

Testing Configuration

  • Configured pytest in pyproject.toml with:
    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting with HTML and XML output
    • Custom markers: unit, integration, and slow
    • Strict mode for markers and configuration
    • Coverage configuration targeting dva, models, datasets, and utils modules

Directory Structure

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

Shared Fixtures (conftest.py)

Created comprehensive fixtures for common testing needs:

  • temp_dir - Temporary directory management
  • sample_config - Mock OmegaConf configuration
  • mock_tensor_data - PyTorch tensor test data
  • mock_numpy_data - NumPy array test data
  • sample_image_path - Test image file creation
  • sample_mesh_data - 3D mesh test data
  • device - PyTorch device selection
  • reset_random_seeds - Reproducible test runs
  • mock_model_weights - Mock model checkpoint files
  • environment_variables - Temporary environment variable management

Additional Configuration

  • Updated .gitignore with:
    • Python-specific entries (.pytest_cache/, .coverage, htmlcov/, etc.)
    • IDE files (.vscode/, .idea/, etc.)
    • Claude-specific entries (.claude/*)
    • Note: poetry.lock is NOT ignored as it should be committed

Validation

  • Created comprehensive validation tests to verify the infrastructure
  • All 17 validation tests pass successfully
  • Both poetry run test and poetry run tests commands are configured

How to Use

  1. Install dependencies:

    poetry install --with dev
  2. Run all tests:

    poetry run pytest
    # or
    poetry run test
    # or
    poetry run tests
  3. Run tests with specific markers:

    poetry run pytest -m unit  # Run only unit tests
    poetry run pytest -m "not slow"  # Skip slow tests
  4. Run tests with coverage:

    poetry run pytest  # Coverage is enabled by default
    poetry run pytest --no-cov  # Disable coverage
  5. View coverage reports:

    • HTML report: open htmlcov/index.html
    • XML report: coverage.xml (for CI integration)

Notes

  • Some dependencies (pymeshlab, triton) may have installation issues on ARM64 architecture, but the core testing infrastructure works properly
  • The Python version is constrained to >=3.9,<3.12 due to dependency requirements
  • Coverage is configured but the fail-under threshold has been removed to avoid issues with empty source files
  • All test infrastructure has been validated and is ready for immediate use

Next Steps

Developers can now start writing tests for the codebase using the established infrastructure. The validation tests serve as examples of how to use the various fixtures and testing features.

- Configure Poetry as package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Create test directory structure (tests/, unit/, integration/)
- Configure pytest with coverage reporting and custom markers
- Add comprehensive shared fixtures in conftest.py
- Update .gitignore with testing and Poetry entries
- 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