From 7fcef07e9ff78efc665b96690ef5cbb13410990e Mon Sep 17 00:00:00 2001 From: Nikita Malinin Date: Tue, 24 Oct 2023 11:09:49 +0200 Subject: [PATCH] Added ov_version parameter to the env tests (#2209) ### Changes - Added `ov_version` variable for the pytest in `test_examples`; - Added `ov_version` variable for the pytest in the `test_install_*`; ### Reason for changes - More flexible tests ### Related tickets - 122860 ### Tests - Updated --- tests/cross_fw/examples/conftest.py | 8 ++++++++ tests/cross_fw/examples/test_examples.py | 16 +++++++++++++++- tests/cross_fw/install/conftest.py | 8 ++++++++ tests/cross_fw/install/test_install.py | 5 +++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/cross_fw/examples/conftest.py b/tests/cross_fw/examples/conftest.py index cbf665402d8..6cac9c21a3e 100644 --- a/tests/cross_fw/examples/conftest.py +++ b/tests/cross_fw/examples/conftest.py @@ -28,6 +28,9 @@ def pytest_addoption(parser): default=False, help="If the parameter is set then the performance metrics will be tested as well", ) + parser.addoption( + "--ov_version_override", default=None, help="Parameter to set OpenVINO into the env with the version from PyPI" + ) @pytest.fixture(scope="module") @@ -38,3 +41,8 @@ def backends_list(request): @pytest.fixture(scope="module") def is_check_performance(request): return request.config.getoption("--check_performance") + + +@pytest.fixture(scope="module") +def ov_version_override(request): + return request.config.getoption("--ov_version_override") diff --git a/tests/cross_fw/examples/test_examples.py b/tests/cross_fw/examples/test_examples.py index fc3c0d8f815..8f98961da15 100644 --- a/tests/cross_fw/examples/test_examples.py +++ b/tests/cross_fw/examples/test_examples.py @@ -11,6 +11,8 @@ import os import subprocess +from pathlib import Path +from typing import Any, Dict, List import pytest @@ -42,7 +44,14 @@ def example_test_cases(): @pytest.mark.parametrize("example_name, example_params", example_test_cases()) -def test_examples(tmp_path, example_name, example_params, backends_list, is_check_performance): +def test_examples( + tmp_path: Path, + example_name: str, + example_params: Dict[str, Any], + backends_list: List[str], + is_check_performance: bool, + ov_version_override: str, +): backend = example_params["backend"] skip_if_backend_not_selected(backend, backends_list) venv_path = create_venv_with_nncf(tmp_path, "pip_e_local", "venv", set([backend])) @@ -52,6 +61,11 @@ def test_examples(tmp_path, example_name, example_params, backends_list, is_chec run_cmd_line = f"{pip_with_venv} install -r {requirements}" subprocess.run(run_cmd_line, check=True, shell=True) + if ov_version_override is not None: + pip_with_venv = get_pip_executable_with_venv(venv_path) + ov_version_cmd_line = f"{pip_with_venv} install {ov_version_override}" + subprocess.run(ov_version_cmd_line, check=True, shell=True) + env = os.environ.copy() env["PYTHONPATH"] = str(PROJECT_ROOT) # need this to be able to import from tests.* in run_example.py diff --git a/tests/cross_fw/install/conftest.py b/tests/cross_fw/install/conftest.py index 5b5142b3acb..179c2fff682 100644 --- a/tests/cross_fw/install/conftest.py +++ b/tests/cross_fw/install/conftest.py @@ -29,6 +29,9 @@ def pytest_addoption(parser): nargs="+", default=["all"], ) + parser.addoption( + "--ov_version_override", default=None, help="Parameter to set OpenVINO into the env with the version from PyPI" + ) @pytest.fixture(scope="module") @@ -39,3 +42,8 @@ def backend_clopt(request): @pytest.fixture(scope="module") def host_configuration_clopt(request): return request.config.getoption("--host-configuration") + + +@pytest.fixture(scope="module") +def ov_version_override(request): + return request.config.getoption("--ov_version_override") diff --git a/tests/cross_fw/install/test_install.py b/tests/cross_fw/install/test_install.py index c7953d2c6f5..bcd015c55ba 100644 --- a/tests/cross_fw/install/test_install.py +++ b/tests/cross_fw/install/test_install.py @@ -107,11 +107,16 @@ def test_install( package_type: str, backend_clopt: List[str], host_configuration_clopt: str, + ov_version_override: str, ): skip_if_backend_not_selected(backend, backend_clopt) if "pypi" in package_type: pytest.xfail("Disabled until NNCF is exposed in a release") venv_path = create_venv_with_nncf(tmp_path, package_type, venv_type, extra_reqs={backend}) + if ov_version_override is not None: + pip_with_venv = get_pip_executable_with_venv(venv_path) + ov_version_cmd_line = f"{pip_with_venv} install {ov_version_override}" + subprocess.run(ov_version_cmd_line, check=True, shell=True) run_install_checks(venv_path, tmp_path, package_type, backend=backend, install_type=host_configuration_clopt) @staticmethod