diff --git a/tests/conditional_compilation/conftest.py b/tests/conditional_compilation/conftest.py index 3a0ae137029f95..c162979bc24222 100644 --- a/tests/conditional_compilation/conftest.py +++ b/tests/conditional_compilation/conftest.py @@ -17,32 +17,30 @@ from pathlib import Path import pytest +import yaml # add ../lib to imports sys.path.insert( 0, str((Path(getsourcefile(lambda: 0)) / ".." / ".." / "lib").resolve(strict=True)) ) -# Using models from https://github.com/openvinotoolkit/testdata -# $find models -wholename "*.xml" -TESTS = [ - {"path": "models/mobilenet_v2_1.4_224/mobilenet_v2_1.4_224_i8.xml"}, - {"path": "models/mobilenet_v2_1.0_224/mobilenet_v2_1.0_224_i8.xml"}, - {"path": "models/inception_v3/inception_v3_i8.xml"}, - {"path": "models/resnet_v1_50/resnet_v1_50_i8.xml"}, - {"path": "models/test_model/test_model_fp16.xml"}, - {"path": "models/test_model/test_model_fp32.xml"}, -] +from path_utils import expand_env_vars # pylint: disable=import-error def pytest_addoption(parser): """ Define extra options for pytest options """ parser.addoption( - "--models_root", required=True, type=Path, help="Path to models root directory" + "--test_conf", + type=Path, + default=Path(__file__).parent / "test_config.yml", + help="Path to models root directory" ) parser.addoption( - "--sea_runtool", required=True, type=Path, help="Path to sea_runtool.py" + "--sea_runtool", + required=True, + type=Path, + help="Path to sea_runtool.py" ) parser.addoption( "--benchmark_app", @@ -65,14 +63,17 @@ def pytest_generate_tests(metafunc): params = [] ids = [] - for test in TESTS: + with open(metafunc.config.getoption('test_conf'), "r") as file: + test_cases = yaml.safe_load(file) + + for test in test_cases: extra_args = {} - path = test["path"] + model_path = expand_env_vars(test["model"]["path"]) if "marks" in test: extra_args["marks"] = test["marks"] - params.append(pytest.param(Path(path), **extra_args)) - ids = ids + [path] + params.append(pytest.param(Path(model_path), **extra_args)) + ids = ids + [model_path] metafunc.parametrize("model", params, ids=ids) @@ -88,12 +89,6 @@ def benchmark_app(request): return request.config.getoption("benchmark_app") -@pytest.fixture(scope="session") -def models_root(request): - """Fixture function for command-line option.""" - return request.config.getoption("models_root") - - @pytest.fixture(scope="session") def artifacts(request): """Fixture function for command-line option.""" diff --git a/tests/conditional_compilation/test_collect.py b/tests/conditional_compilation/test_collect.py index 4088c2f7d220a8..4f85b8efcf4e6e 100644 --- a/tests/conditional_compilation/test_collect.py +++ b/tests/conditional_compilation/test_collect.py @@ -11,7 +11,7 @@ from proc_utils import cmd_exec # pylint: disable=import-error -def test_cc_collect(model, sea_runtool, benchmark_app, models_root, artifacts): +def test_cc_collect(model, sea_runtool, benchmark_app, artifacts): """ Test conditional compilation statistics collection """ out = artifacts / model.parent / model.stem @@ -29,7 +29,7 @@ def test_cc_collect(model, sea_runtool, benchmark_app, models_root, artifacts): "!", str(benchmark_app), "-d=CPU", - f"-m={models_root / model}", + f"-m={model}", "-niter=1", "-nireq=1", ] diff --git a/tests/conditional_compilation/test_infer.py b/tests/conditional_compilation/test_infer.py index b7d66f72015233..85df816b94fc86 100644 --- a/tests/conditional_compilation/test_infer.py +++ b/tests/conditional_compilation/test_infer.py @@ -8,10 +8,10 @@ from proc_utils import cmd_exec # pylint: disable=import-error -def test_infer(model, models_root, benchmark_app): +def test_infer(model, benchmark_app): """ Test inference with conditional compiled binaries """ returncode, _ = cmd_exec( - [str(benchmark_app), "-d=CPU", f"-m={models_root / model}", "-niter=1", "-nireq=1"] + [str(benchmark_app), "-d=CPU", f"-m={model}", "-niter=1", "-nireq=1"] ) assert returncode == 0, f"Command exited with non-zero status {returncode}" diff --git a/tests/lib/path_utils.py b/tests/lib/path_utils.py new file mode 100644 index 00000000000000..f65182761e20d0 --- /dev/null +++ b/tests/lib/path_utils.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +# Copyright (C) 2021 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +""" Common utilities for working with processes. +""" + +import os + + +def expand_env_vars(obj): + """Expand environment variables in provided object.""" + + if isinstance(obj, list): + for i, value in enumerate(obj): + obj[i] = expand_env_vars(value) + elif isinstance(obj, dict): + for name, value in obj.items(): + obj[name] = expand_env_vars(value) + else: + obj = os.path.expandvars(obj) + return obj