Link to this sectionCI/Testing Workflow ๐งช#
Continuous Integration (CI) is essential for maintaining high-quality code by catching issues early. This guide covers CI testing and quality checks for Ultralytics projects.
Link to this sectionCI Actions ๐#
All PRs must pass automated CI checks before merging. Our CI pipeline includes:
Link to this sectionCI Tests#
Primary CI test running unit tests, linting checks, and comprehensive tests.
Link to this sectionDocker Deployment#
Validates deployment using Docker, ensuring Dockerfile and related scripts work correctly.
Link to this sectionBroken Links#
Scans codebase for broken or dead links in markdown and HTML files.
Link to this sectionCodeQL Analysis#
GitHub's semantic analysis tool for finding potential security vulnerabilities and maintaining code quality.
Link to this sectionPyPI Publishing#
Validates project can be packaged and published to PyPI without errors.
Link to this sectionPlatform Testing ๐ฅ๏ธ#
Tests run on multiple environments:
- OS: Ubuntu, Windows, macOS
- Python: 3.8, 3.9, 3.10, 3.11, 3.12
Link to this sectionCode Coverage ๐#
We use Codecov to measure and visualize code coverage, providing insights into how well tests exercise the codebase.
Link to this sectionCoverage Integration#
Codecov integration provides:
- Detailed coverage insights
- Coverage comparisons between commits
- Visual overlays on code showing covered lines
- Coverage percentage for the
ultralyticspackage
View full coverage details at codecov.io/github/ultralytics/ultralytics.
Link to this sectionUnderstanding Coverage#
Code coverage shows what percentage of code is executed during tests. High coverage indicates well-tested code but doesn't guarantee absence of bugs. Coverage helps identify untested areas that might be prone to errors.
Link to this sectionRunning Tests Locally ๐ฅ๏ธ#
Link to this sectionInstall Development Dependencies#
pip install -e ".[dev]"Link to this sectionRun All Tests#
pytest tests/Link to this sectionRun Specific Tests#
# Single file
pytest tests/test_engine.py
# Single test function
pytest tests/test_engine.py::test_train
# Tests matching pattern
pytest -k "export"
# Slow tests only
pytest -m slowLink to this sectionRun with Coverage#
pytest --cov=ultralytics tests/Link to this sectionParallel Testing#
# Install pytest-xdist
pip install pytest-xdist
# Run tests in parallel
pytest -n autoLink to this sectionWriting Tests โ๏ธ#
Link to this sectionTest Structure#
from pathlib import Path
from ultralytics import YOLO
def test_model_export():
"""Test ONNX model export."""
model = YOLO("yolo26n.pt")
model.export(format="onnx")
assert Path("yolo26n.onnx").exists()Link to this sectionBest Practices#
- Descriptive names:
test_export_onnx_format()nottest_1() - Single assertion: Test one thing per function
- Fast tests: Use small models/datasets
- Fixtures: Use pytest fixtures for setup/teardown
- Markers:
@pytest.mark.slowfor long-running tests
Link to this sectionTest Organization#
tests/
โโโ test_engine.py # Training, validation, prediction
โโโ test_nn.py # Model architecture
โโโ test_data.py # Dataset handling
โโโ test_utils.py # Utility functions
โโโ test_exports.py # Export formatsLink to this sectionTest Markers#
import pytest
@pytest.mark.slow
def test_full_training():
"""Test full training run (slow)."""
model = YOLO("yolo26n.pt")
model.train(data="coco128.yaml", epochs=1)Link to this sectionCode Quality Checks ๐ฏ#
Link to this sectionFormatting with Ruff#
# Check formatting
ruff check ultralytics/
# Auto-fix issues
ruff check --fix ultralytics/
# Format code
ruff format ultralytics/Learn more about code standards in our development workflow.
Link to this sectionType Checking#
# Run mypy (where configured)
mypy ultralytics/Link to this sectionDocstring Formatting#
pip install ultralytics-actions# Auto-fix
ultralytics-actions-format-python-docstrings .Link to this sectionCI Troubleshooting ๐ง#
Link to this sectionTests Pass Locally But Fail in CI#
Common causes:
- Platform-specific issues: Test on target OS
- Python version differences: Check version compatibility
- Missing dependencies: Verify CI config
- Timing/concurrency issues: Add retries or increase timeouts
Link to this sectionSlow CI Runs#
Solutions:
- Use
@pytest.mark.slowfor expensive tests - Mock external dependencies
- Reduce test dataset sizes
- Parallelize with
pytest-xdist
Link to this sectionFlaky Tests#
Fixes:
- Add retries for network-dependent tests
- Increase timeouts for slow operations
- Fix race conditions in async code
- Use deterministic random seeds
Link to this sectionPerformance Benchmarks ๐#
CI tracks key metrics:
- Inference speed (FPS)
- Memory usage
- Model size
- Export times
Significant regressions block merging. If metrics change:
- Verify change is expected
- Document reason in PR
- Get approval from maintainers
Link to this sectionCI Status ๐#
Check CI status for all Ultralytics repositories at docs.ultralytics.com/help/CI.
Link to this sectionMain Repository Badges#
Link to this sectionSkipping CI Checks โ ๏ธ#
Add [skip ci] to commit message to skip CI (use sparingly):
git commit -m "Update README [skip ci]"Only for:
- Documentation-only changes
- Non-code file updates
- Emergency hotfixes (with approval)
Link to this sectionResources ๐#
- Official CI Guide - Complete CI documentation
- Development Workflow - PR process and code standards
- GitHub Actions Docs - CI configuration
- pytest Documentation - Testing framework
- Codecov - Coverage reports