Skip to content

chore: Set up Python testing infrastructure with Poetry and pytest #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 14, 2025

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

- Add Poetry package management with pyproject.toml configuration
- Configure pytest with coverage reporting (80% threshold)
- Create test directory structure (unit/integration)
- Add comprehensive test fixtures in conftest.py
- Update .gitignore for testing artifacts and Poetry
- Add validation tests to verify 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