Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions model_api/tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def pytest_addoption(parser):
default="",
help="directory to store inference result",
)
parser.addoption(
"--only-model-type",
action="store",
default="",
help="select model type to run tests on (and all that inherit from it)",
)
Comment thread
tybulewicz marked this conversation as resolved.


def pytest_configure(config):
Expand Down
19 changes: 17 additions & 2 deletions model_api/tests/functional/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import json
import operator
from pathlib import Path
from typing import Type

import cv2
import numpy as np
Expand All @@ -32,6 +33,7 @@
InstanceSegmentationResult,
KeypointDetectionModel,
MaskRCNNModel,
Model,
Prompt,
SAMDecoder,
SAMImageEncoder,
Expand Down Expand Up @@ -145,6 +147,14 @@ def model_data_file(pytestconfig):
return pytestconfig.getoption("model_data")


@pytest.fixture(scope="session")
def only_model_class(pytestconfig) -> Type[Model] | None:
model_type = pytestconfig.getoption("only_model_type")
if not model_type:
return None
return Model.get_model_class(model_type)


def pytest_generate_tests(metafunc):
if "model_data" in metafunc.fixturenames:
model_data_file = metafunc.config.getoption("model_data")
Expand Down Expand Up @@ -416,13 +426,18 @@ def assert_contours_match(actual: list[dict], expected: list[dict]) -> None:
)


def test_image_models(data, device, dump, result, model_data, results_dir): # noqa: C901
def test_image_models(data, device, dump, result, model_data, results_dir, only_model_class): # noqa: C901
name = model_data["name"]

model_type = MODEL_TYPE_MAPPING[model_data["type"]]
if only_model_class and not issubclass(model_type, only_model_class):
pytest.skip(f"Skipping {name} as it is not a subclass of {only_model_class.__name__}")

if name.endswith((".xml", ".onnx")):
name = f"{data}/{name}"

for model in create_models(
MODEL_TYPE_MAPPING[model_data["type"]],
model_type,
name,
data,
model_data.get("force_ort", False),
Expand Down