mirror of
https://github.com/ultralytics/ultralytics
synced 2026-04-21 14:07:18 +00:00
Some checks are pending
CI / Benchmarks (yolo26n, macos-26, 3.12) (push) Waiting to run
CI / Benchmarks (yolo26n, ubuntu-24.04-arm, 3.12) (push) Waiting to run
CI / Benchmarks (yolo26n, ubuntu-latest, 3.12) (push) Waiting to run
CI / Tests (macos-26, 3.12, latest) (push) Waiting to run
CI / Tests (ubuntu-24.04-arm, 3.12, latest) (push) Waiting to run
CI / Tests (ubuntu-latest, 3.12, latest) (push) Waiting to run
CI / Tests (ubuntu-latest, 3.8, 1.8.0, 0.9.0) (push) Waiting to run
CI / Tests (windows-latest, 3.12, latest) (push) Waiting to run
CI / SlowTests (macos-26, 3.12, latest) (push) Waiting to run
CI / SlowTests (ubuntu-24.04-arm, 3.12, latest) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.10, 1.11.0, 0.12.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.10, 1.12.0, 0.13.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.10, 1.13.0, 0.14.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.11, 2.0.0, 0.15.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.11, 2.1.0, 0.16.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.12, 2.10.0, 0.25.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.12, 2.11.0, 0.26.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.12, 2.2.0, 0.17.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.12, 2.3.0, 0.18.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.12, 2.4.0, 0.19.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.12, 2.5.0, 0.20.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.12, 2.6.0, 0.21.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.12, 2.7.0, 0.22.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.12, 2.8.0, 0.23.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.12, 2.9.0, 0.24.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.12, latest) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.8, 1.8.0, 0.9.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.9, 1.10.0, 0.11.0) (push) Waiting to run
CI / SlowTests (ubuntu-latest, 3.9, 1.9.0, 0.10.0) (push) Waiting to run
CI / SlowTests (windows-latest, 3.12, latest) (push) Waiting to run
CI / GPU (push) Waiting to run
CI / RaspberryPi (push) Waiting to run
CI / NVIDIA_Jetson (JetPack5.1.2, 1.23.5, https://github.com/ultralytics/assets/releases/download/v0.0.0/onnxruntime_gpu-1.16.3-cp38-cp38-linux_aarch64.whl, 3.8, jetson-jp512, https://github.com/ultralytics/assets/releases/download/v0.0.0/torch-2.2.0-cp38-c… (push) Waiting to run
CI / NVIDIA_Jetson (JetPack6.2, 1.26.4, https://github.com/ultralytics/assets/releases/download/v0.0.0/onnxruntime_gpu-1.20.0-cp310-cp310-linux_aarch64.whl, 3.10, jetson-jp62, https://github.com/ultralytics/assets/releases/download/v0.0.0/torch-2.5.0a0+872d… (push) Waiting to run
CI / Conda (ubuntu-latest, 3.12) (push) Waiting to run
CI / Summary (push) Blocked by required conditions
Publish Docker Images / Build (push) Waiting to run
Publish Docker Images / trigger-actions (push) Blocked by required conditions
Publish Docker Images / notify (push) Blocked by required conditions
Publish Docs / Docs (push) Waiting to run
Publish to PyPI / check (push) Waiting to run
Publish to PyPI / build (push) Blocked by required conditions
Publish to PyPI / publish (push) Blocked by required conditions
Publish to PyPI / sbom (push) Blocked by required conditions
Publish to PyPI / notify (push) Blocked by required conditions
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
102 lines
3.8 KiB
Python
102 lines
3.8 KiB
Python
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
|
|
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
def solution_assets():
|
|
"""Session-scoped fixture to cache solution test assets.
|
|
|
|
Lazily downloads solution assets into a persistent directory (WEIGHTS_DIR/solution_assets) and returns a callable
|
|
that resolves asset names to cached paths.
|
|
"""
|
|
from ultralytics.utils import ASSETS_URL, WEIGHTS_DIR
|
|
from ultralytics.utils.downloads import safe_download
|
|
|
|
# Use persistent directory alongside weights
|
|
cache_dir = WEIGHTS_DIR / "solution_assets"
|
|
cache_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Define all assets needed for solution tests
|
|
assets = {
|
|
# Videos
|
|
"demo_video": "solutions_ci_demo.mp4",
|
|
"crop_video": "decelera_landscape_min.mov",
|
|
"pose_video": "solution_ci_pose_demo.mp4",
|
|
"parking_video": "solution_ci_parking_demo.mp4",
|
|
"vertical_video": "solution_vertical_demo.mp4",
|
|
# Parking manager files
|
|
"parking_areas": "solution_ci_parking_areas.json",
|
|
"parking_model": "solutions_ci_parking_model.pt",
|
|
}
|
|
|
|
asset_paths = {}
|
|
|
|
def get_asset(name):
|
|
"""Return the cached path for a named solution asset, downloading it on first use."""
|
|
if name not in asset_paths:
|
|
asset_path = cache_dir / assets[name]
|
|
if not asset_path.exists():
|
|
safe_download(url=f"{ASSETS_URL}/{asset_path.name}", dir=cache_dir)
|
|
asset_paths[name] = asset_path
|
|
return asset_paths[name]
|
|
|
|
return get_asset
|
|
|
|
|
|
def pytest_addoption(parser):
|
|
"""Add custom command-line options to pytest."""
|
|
parser.addoption("--slow", action="store_true", default=False, help="Run slow tests")
|
|
|
|
|
|
def pytest_collection_modifyitems(config, items):
|
|
"""Modify the list of test items to exclude tests marked as slow if the --slow option is not specified.
|
|
|
|
Args:
|
|
config: The pytest configuration object that provides access to command-line options.
|
|
items (list): The list of collected pytest item objects to be modified based on the presence of --slow option.
|
|
"""
|
|
if not config.getoption("--slow"):
|
|
# Remove the item entirely from the list of test items if it's marked as 'slow'
|
|
items[:] = [item for item in items if "slow" not in item.keywords]
|
|
|
|
|
|
def pytest_sessionstart(session):
|
|
"""Initialize session configurations for pytest.
|
|
|
|
This function is automatically called by pytest after the 'Session' object has been created but before performing
|
|
test collection. It sets the initial seeds for the test session.
|
|
|
|
Args:
|
|
session: The pytest session object.
|
|
"""
|
|
from ultralytics.utils.torch_utils import init_seeds
|
|
|
|
init_seeds()
|
|
|
|
|
|
def pytest_terminal_summary(terminalreporter, exitstatus, config):
|
|
"""Cleanup operations after pytest session.
|
|
|
|
This function is automatically called by pytest at the end of the entire test session. It removes certain files and
|
|
directories used during testing.
|
|
|
|
Args:
|
|
terminalreporter: The terminal reporter object used for terminal output.
|
|
exitstatus (int): The exit status of the test run.
|
|
config: The pytest config object.
|
|
"""
|
|
from ultralytics.utils import WEIGHTS_DIR
|
|
|
|
# Remove files
|
|
models = [path for x in {"*.onnx", "*.torchscript"} for path in WEIGHTS_DIR.rglob(x)]
|
|
for file in ["decelera_portrait_min.mov", "bus.jpg", "yolo26n.onnx", "yolo26n.torchscript", *models]:
|
|
Path(file).unlink(missing_ok=True)
|
|
|
|
# Remove directories
|
|
models = [path for x in {"*.mlpackage", "*_openvino_model"} for path in WEIGHTS_DIR.rglob(x)]
|
|
for directory in [WEIGHTS_DIR / "solution_assets", WEIGHTS_DIR / "path with spaces", *models]:
|
|
shutil.rmtree(directory, ignore_errors=True)
|