HashNeRF-pytorch icon indicating copy to clipboard operation
HashNeRF-pytorch copied to clipboard

chore: Set up Python testing infrastructure with Poetry and pytest

Open llbbl opened this issue 6 months ago • 0 comments

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the HashNeRF-pytorch project using Poetry for dependency management and pytest for testing.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry as the package manager
  • Dependencies: Migrated all project dependencies (torch, numpy, imageio, etc.) to Poetry
  • Optional Dependencies: Made pyvista optional (installable with poetry install -E scannet) due to platform compatibility issues
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Configuration

  • pytest Configuration:

    • Configured test discovery patterns
    • Set up coverage reporting with 80% threshold
    • Added custom markers: unit, integration, slow
    • Configured HTML and XML coverage reports
    • Added strict mode and verbose output
  • Coverage Configuration:

    • Excluded test files, scripts, and config from coverage
    • Set up multiple report formats (terminal, HTML, XML)
    • Configured coverage fail threshold at 80%

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures
├── test_setup_validation.py  # Validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Test Fixtures (conftest.py)

Created comprehensive fixtures for:

  • Temporary directories and files
  • Mock configurations
  • Sample data (images, poses, rays)
  • Mock models and encodings
  • Device management
  • GPU cleanup
  • Log capturing

Commands

  • poetry install - Install all dependencies
  • poetry run test or poetry run tests - Run all tests
  • poetry run pytest [options] - Run tests with custom options

Additional Updates

  • Updated .gitignore with:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
    • Poetry lock file (as recommended)
    • Claude settings (.claude/*)
    • IDE and OS files

Testing the Setup

  1. Install dependencies:

    poetry install
    
  2. Run validation tests:

    poetry run test
    
  3. Run with coverage:

    poetry run pytest --cov=. --cov-report=html
    

Notes

  • The validation test test_imports may fail in environments without CUDA due to module-level CUDA initialization in the codebase
  • pyvista is optional due to VTK dependency issues on some platforms
  • All pytest standard options are available through the Poetry commands
  • Coverage threshold is set to 80% but can be adjusted in pyproject.toml

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures for common testing needs
  4. Run tests with coverage reporting to ensure code quality

llbbl avatar Jun 14 '25 13:06 llbbl