From 1c64b277cc19fb1b6ab6039571aceeba7a33fe29 Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Wed, 8 May 2024 09:56:25 +0100 Subject: [PATCH] Skip tests at an earlier stage --- tests/pytests/pkg/conftest.py | 14 +++++++++++++- tests/pytests/pkg/downgrade/test_salt_downgrade.py | 4 ---- tests/pytests/pkg/upgrade/test_salt_upgrade.py | 4 ---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/tests/pytests/pkg/conftest.py b/tests/pytests/pkg/conftest.py index ccc14bb7eb8..699b9162189 100644 --- a/tests/pytests/pkg/conftest.py +++ b/tests/pytests/pkg/conftest.py @@ -119,8 +119,9 @@ def pytest_runtest_setup(item): """ Fixtures injection based on markers or test skips based on CLI arguments """ + pkg_tests_path = pathlib.Path(__file__).parent if ( - str(item.fspath).startswith(str(pathlib.Path(__file__).parent / "download")) + str(item.fspath).startswith(str(pkg_tests_path / "download")) and item.config.getoption("--download-pkgs") is False ): raise pytest.skip.Exception( @@ -129,6 +130,17 @@ def pytest_runtest_setup(item): _use_item_location=True, ) + for key in ("upgrade", "downgrade"): + if ( + str(item.fspath).startswith(str(pkg_tests_path / key)) + and item.config.getoption(f"--{key}") is False + ): + raise pytest.skip.Exception( + f"The package {key} tests are disabled. Pass '--{key}' to pytest " + "to enable them.", + _use_item_location=True, + ) + @pytest.fixture(scope="session") def salt_factories_root_dir(request, tmp_path_factory): diff --git a/tests/pytests/pkg/downgrade/test_salt_downgrade.py b/tests/pytests/pkg/downgrade/test_salt_downgrade.py index 43fe1cc30dd..adba7c51272 100644 --- a/tests/pytests/pkg/downgrade/test_salt_downgrade.py +++ b/tests/pytests/pkg/downgrade/test_salt_downgrade.py @@ -1,6 +1,5 @@ import packaging.version import psutil -import pytest from pytestskipmarkers.utils import platform @@ -8,9 +7,6 @@ def test_salt_downgrade(salt_call_cli, install_salt): """ Test an upgrade of Salt. """ - if not install_salt.downgrade: - pytest.skip("Not testing a downgrade, do not run") - is_downgrade_to_relenv = packaging.version.parse( install_salt.prev_version ) >= packaging.version.parse("3006.0") diff --git a/tests/pytests/pkg/upgrade/test_salt_upgrade.py b/tests/pytests/pkg/upgrade/test_salt_upgrade.py index 4aceb0acab8..7eeeb00c10e 100644 --- a/tests/pytests/pkg/upgrade/test_salt_upgrade.py +++ b/tests/pytests/pkg/upgrade/test_salt_upgrade.py @@ -2,7 +2,6 @@ import logging import packaging.version import psutil -import pytest from pytestskipmarkers.utils import platform log = logging.getLogger(__name__) @@ -26,9 +25,6 @@ def test_salt_upgrade(salt_call_cli, install_salt): """ Test an upgrade of Salt. """ - if not install_salt.upgrade: - pytest.skip("Not testing an upgrade, do not run") - if install_salt.relenv: original_py_version = install_salt.package_python_version()