mirror of
https://github.com/azaion/ai-training.git
synced 2026-04-23 05:36:35 +00:00
[AZ-171] Add TensorRT tests, AC coverage gate in implement skill, optimize test infrastructure
- Add TensorRT export tests with graceful skip when no GPU available - Add AC test coverage verification step (Step 8) to implement skill - Add test coverage gap analysis to new-task skill - Move exported_models fixture to conftest.py as session-scoped (shared across modules) - Reorder tests: e2e training runs first so images/labels are available for all tests - Consolidate teardown into single session-level cleanup in conftest.py - Fix infrastructure tests to count files dynamically instead of hardcoded 20 Made-with: Cursor
This commit is contained in:
+54
-9
@@ -1,5 +1,6 @@
|
||||
import csv
|
||||
import shutil
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
@@ -12,12 +13,21 @@ _DATASET_LABELS = _TEST_ROOT / "data" / "labels"
|
||||
_ONNX_MODEL = _PROJECT_ROOT / "_docs/00_problem/input_data/azaion.onnx"
|
||||
_CLASSES_JSON = _PROJECT_ROOT / "src" / "classes.json"
|
||||
_CONFIG_TEST = _PROJECT_ROOT / "config.test.yaml"
|
||||
_MODELS_DIR = _TEST_ROOT / "models"
|
||||
|
||||
collect_ignore = ["security_test.py", "imagelabel_visualize_test.py"]
|
||||
|
||||
_E2E_MODULE = "test_training_e2e"
|
||||
|
||||
_test_results = []
|
||||
|
||||
|
||||
def pytest_collection_modifyitems(items):
|
||||
e2e = [i for i in items if _E2E_MODULE in i.nodeid]
|
||||
rest = [i for i in items if _E2E_MODULE not in i.nodeid]
|
||||
items[:] = e2e + rest
|
||||
|
||||
|
||||
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
||||
def pytest_runtest_makereport(item, call):
|
||||
outcome = yield
|
||||
@@ -32,16 +42,21 @@ def pytest_runtest_makereport(item, call):
|
||||
|
||||
|
||||
def pytest_sessionfinish(session, exitstatus):
|
||||
if not _test_results:
|
||||
return
|
||||
results_dir = Path(__file__).resolve().parent / "test-results"
|
||||
results_dir.mkdir(exist_ok=True)
|
||||
if _test_results:
|
||||
results_dir = Path(__file__).resolve().parent / "test-results"
|
||||
results_dir.mkdir(exist_ok=True)
|
||||
|
||||
with open(results_dir / "test-results.csv", "w", newline="", encoding="utf-8") as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(["module", "test", "result", "duration_s"])
|
||||
for r in _test_results:
|
||||
writer.writerow([r["module"], r["name"], r["result"], f"{r['duration']:.3f}"])
|
||||
with open(results_dir / "test-results.csv", "w", newline="", encoding="utf-8") as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(["module", "test", "result", "duration_s"])
|
||||
for r in _test_results:
|
||||
writer.writerow([r["module"], r["name"], r["result"], f"{r['duration']:.3f}"])
|
||||
|
||||
import constants as c
|
||||
test_config = c.Config.from_yaml(str(_CONFIG_TEST), root=str(_TEST_ROOT))
|
||||
for d in (_DATASET_IMAGES, _DATASET_LABELS, test_config.datasets_dir,
|
||||
test_config.corrupted_dir, str(_MODELS_DIR)):
|
||||
shutil.rmtree(str(d), ignore_errors=True)
|
||||
|
||||
|
||||
def apply_constants_patch(monkeypatch, base: Path):
|
||||
@@ -157,3 +172,33 @@ def empty_label(tmp_path):
|
||||
p.parent.mkdir(parents=True, exist_ok=True)
|
||||
p.write_text("", encoding="utf-8")
|
||||
return p
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def exported_models():
|
||||
from ultralytics import YOLO
|
||||
import constants as c
|
||||
import exports as exports_mod
|
||||
|
||||
_MODELS_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
pt_path = str(_MODELS_DIR / "test.pt")
|
||||
YOLO("yolo11n.pt").save(pt_path)
|
||||
|
||||
old_config = c.config
|
||||
c.config = c.Config.from_yaml(str(_CONFIG_TEST), root=str(_TEST_ROOT))
|
||||
imgsz = c.config.export.onnx_imgsz
|
||||
|
||||
exports_mod.export_onnx(pt_path)
|
||||
if sys.platform == "darwin":
|
||||
exports_mod.export_coreml(pt_path)
|
||||
|
||||
c.config = old_config
|
||||
|
||||
onnx_files = list(_MODELS_DIR.glob("test*.onnx"))
|
||||
return {
|
||||
"onnx": str(onnx_files[0]) if onnx_files else None,
|
||||
"model_dir": _MODELS_DIR,
|
||||
"pt_path": pt_path,
|
||||
"imgsz": imgsz,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user