Quick guide for running tests in this project.
Note
Integration and full pipeline tests likely requires specific
neuroimaging tools that can be called with niwrap. To perform
these tests, also pass the --runner flag to pytest.
# Install dependencies
pip install -e ".[dev]"
# Run fast tests (recommended during development)
pytest -m unit
# Run all tests (except slow ones)
pytest -m "not slow and not full_pipeline" --runner <local|docker|singularity>
# Run everything
pytest --runner <local|docker|singularity>| Marker | Speed |
|---|---|
unit |
<1s per test |
integration |
1-5 min |
slow |
>5 min |
full_pipeline |
30+ min |
# Fast feedback loop (unit tests only)
pytest -m unit
# Test specific file
pytest tests/unit/test_bids_parsing.py
# Test specific function
pytest tests/unit/test_bids_parsing.py::test_parse_subject_id# Stop on first failure
pytest -x
# Show which tests are slowest
pytest --durations=10
# Run tests matching a pattern
pytest -k "motion_correction"Test data is stored in tests/data/.
- Overall: >85%
- Unit tests: >90%
- Integration tests: >80%
# Check coverage
pytest --cov=src --cov-report=term-missing
# Generate HTML report
pytest --cov=src --cov-report=htmlTests run automatically on GitHub Actions:
- On every push: Unit tests + fast integration tests
- Manual trigger: Full pipeline tests (slow)
To run the same tests as CI locally:
pytest -m "not slow and not full_pipeline" \
--cov=src \
--cov-report=xml \
--junitxml=pytest.xmltests/
├── conftest.py # Shared fixtures
├── unit/ # Fast tests (<1s)
├── integration/ # Medium tests (1-5 min)
├── full_pipeline/ # Slow tests (30+ min)
└── data/ # Test datasets
- Run unit tests frequently - They're fast (<1s)
- Run integration tests before committing - Catch issues early
- Use appropriate markers - Auto-applied based on file location
- Write descriptive test names -
test_motion_correction_preserves_dimensions - One assertion per test - When practical
- Use fixtures - Don't repeat setup code
- Keep tests independent - No shared state between tests