Skip tests at an earlier stage

This commit is contained in:
Pedro Algarvio 2024-05-08 09:56:25 +01:00
parent 32ed717ee8
commit 1c64b277cc
3 changed files with 13 additions and 9 deletions

View file

@ -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):

View file

@ -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")

View file

@ -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()