Vista
Vista copied to clipboard
feat: Set up comprehensive Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the VISTA project, migrating from traditional pip/requirements.txt to Poetry for modern dependency management and setting up pytest with coverage reporting.
Changes Made
Package Management
- Migrated to Poetry: Created
pyproject.tomlwith all dependencies fromrequirements.txt - Preserved all dependencies: Maintained exact dependency specifications including version constraints
- Added development dependencies: pytest, pytest-cov, and pytest-mock
Testing Configuration
-
pytest configuration in
pyproject.toml:- Test discovery patterns for
test_*.pyand*_test.pyfiles - Coverage reporting with 80% threshold requirement
- Multiple output formats: terminal, HTML, and XML reports
- Custom markers:
unit,integration, andslow - Strict mode enabled with verbose output
- Test discovery patterns for
-
Coverage configuration:
- Source set to
vwmpackage - Branch coverage enabled
- Exclusions for test files,
__init__.py, and common patterns - HTML reports in
htmlcov/directory - XML reports for CI integration
- Source set to
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_setup_validation.py # Infrastructure validation
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Test Fixtures (conftest.py)
temp_dir: Temporary directory for test filesmock_config: OmegaConf configuration for testingsample_tensor: Sample PyTorch tensorssample_video_tensor: Video tensors for temporal modelsmock_dataset_item: Mock dataset itemsmock_model_state: Model state dictionariesdevice: CPU/GPU device selectionmock_checkpoint_path: Checkpoint pathsreset_random_seeds: Reproducible testsmock_wandb: Mocked Weights & Biasesmock_env_vars: Test environment variablescapture_stdout: Output capture utility
Additional Setup
- Updated
.gitignorewith:- Testing artifacts (
.pytest_cache/,.coverage,htmlcov/,coverage.xml) - Claude settings (
.claude/*) - IDE files (VSCode workspace files)
- Testing artifacts (
- Created validation tests to verify the infrastructure
How to Use
Install Dependencies
poetry install --with dev
Run Tests
Both commands work identically:
poetry run test
# or
poetry run tests
Run with Options
# Run specific tests
poetry run test tests/unit/
# Run with markers
poetry run test -m unit
poetry run test -m "not slow"
# Run without coverage
poetry run test --no-cov
# Run specific test file
poetry run test tests/test_setup_validation.py
Coverage Reports
- Terminal: Shown by default after test run
- HTML: Open
htmlcov/index.htmlin browser - XML: Available at
coverage.xmlfor CI tools
Notes
- The infrastructure is ready for developers to start writing tests
- No actual unit tests for the codebase were created - only infrastructure setup
- Poetry lock file should be committed to ensure reproducible builds
- Coverage threshold is set to 80% but can be adjusted in
pyproject.toml - The validation test that imports the main package may fail due to missing optional dependencies (like
open_clip), but this doesn't affect the testing infrastructure itself
Next Steps
- Developers can now create unit tests in
tests/unit/ - Integration tests go in
tests/integration/ - Use the provided fixtures in
conftest.pyfor common test needs - Mark slow tests with
@pytest.mark.slowto exclude them during rapid development