HashNeRF-pytorch
HashNeRF-pytorch copied to clipboard
chore: Set up Python testing infrastructure with Poetry and pytest
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.tomlwith 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 dependenciespoetry run testorpoetry run tests- Run all testspoetry run pytest [options]- Run tests with custom options
Additional Updates
- Updated
.gitignorewith:- Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
- Poetry lock file (as recommended)
- Claude settings (.claude/*)
- IDE and OS files
Testing the Setup
-
Install dependencies:
poetry install -
Run validation tests:
poetry run test -
Run with coverage:
poetry run pytest --cov=. --cov-report=html
Notes
- The validation test
test_importsmay 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:
- Write unit tests in
tests/unit/ - Write integration tests in
tests/integration/ - Use the provided fixtures for common testing needs
- Run tests with coverage reporting to ensure code quality