Switch to a custom timeout_unless_on_windows marker

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2024-01-23 07:00:32 +00:00 committed by Pedro Algarvio
parent 67a0e99bff
commit 5f63d785e9
12 changed files with 35 additions and 22 deletions

View file

@ -338,6 +338,11 @@ def pytest_configure(config):
"when called returns `True`. If `skip` is a callable, it should accept a single argument "
"'grains', which is the grains dictionary.",
)
config.addinivalue_line(
"markers",
"timeout_unless_on_windows(*args, **kwargs): Apply the 'timeout' marker unless running "
"on Windows.",
)
# "Flag" the slowTest decorator if we're skipping slow tests or not
os.environ["SLOW_TESTS"] = str(config.getoption("--run-slow"))
@ -451,16 +456,24 @@ def pytest_collection_modifyitems(config, items):
str(PYTESTS_DIR / "scenarios"),
)
for item in items:
if (
not salt.utils.platform.is_windows()
and not str(pathlib.Path(item.fspath).resolve()).startswith(
timeout_marker_tests_paths
)
and not item.get_closest_marker("timeout")
):
# Let's apply the timeout marker on the test, if the marker
# is not already applied
item.add_marker(pytest.mark.timeout(60))
marker = item.get_closest_marker("timeout_unless_on_windows")
if marker is not None:
if not salt.utils.platform.is_windows():
# Apply the marker since we're not on windows
item.add_marker(
pytest.mark.timeout(*marker.args, **marker.kwargs.copy())
)
else:
if (
not salt.utils.platform.is_windows()
and not str(pathlib.Path(item.fspath).resolve()).startswith(
timeout_marker_tests_paths
)
and not item.get_closest_marker("timeout")
):
# Let's apply the timeout marker on the test, if the marker
# is not already applied
item.add_marker(pytest.mark.timeout(60))
for fixture in item.fixturenames:
if fixture not in item._fixtureinfo.name2fixturedefs:
continue

View file

@ -13,7 +13,7 @@ class LoaderOverridesTest(ModuleCase):
self.run_function("saltutil.sync_modules")
@pytest.mark.slow_test
@pytest.mark.timeout(120)
@pytest.mark.timeout_unless_on_windows(120)
def test_overridden_internal(self):
# To avoid a race condition on Windows, we need to make sure the
# `override_test.py` file is present in the _modules directory before

View file

@ -36,7 +36,7 @@ class SPMBuildTest(SPMCase, ModuleCase):
@pytest.mark.skip_if_binaries_missing("fallocate")
@pytest.mark.slow_test
@pytest.mark.timeout(120)
@pytest.mark.timeout_unless_on_windows(120)
def test_spm_build_big_file(self):
"""
test spm build with a big file

View file

@ -9,7 +9,7 @@ from tests.support.pytest.helpers import FakeSaltExtension
pytestmark = [
# These are slow because they create a virtualenv and install salt in it
pytest.mark.slow_test,
pytest.mark.timeout(120),
pytest.mark.timeout_unless_on_windows(120),
]

View file

@ -55,7 +55,7 @@ def npm(states, modules, apply_gitconfig_workaround):
@pytest.mark.skip_if_not_root
@pytest.mark.timeout(120)
@pytest.mark.timeout_unless_on_windows(120)
def test_removed_installed_cycle(npm, modules):
project_version = "pm2@5.1.0"
success = modules.npm.uninstall("pm2")

View file

@ -19,7 +19,7 @@ pytestmark = [
pytest.mark.slow_test,
pytest.mark.skip_if_not_root,
pytest.mark.destructive_test,
pytest.mark.timeout(120),
pytest.mark.timeout_unless_on_windows(120),
]

View file

@ -592,7 +592,7 @@ def ping():
[True, False],
ids=["parallel_startup=True", "parallel_startup=False"],
)
@pytest.mark.timeout(120)
@pytest.mark.timeout_unless_on_windows(120)
def test_custom_proxy_module_raise_exception(
salt_master,
salt_cli,

View file

@ -12,7 +12,7 @@ docker = pytest.importorskip("docker")
pytestmark = [
pytest.mark.core_test,
pytest.mark.timeout(120),
pytest.mark.timeout_unless_on_windows(120),
]

View file

@ -106,7 +106,7 @@ def test_grains_append_val_is_list(salt_call_cli, append_grain):
assert ret.data == {append_grain.key: [append_grain.value, second_grain]}
@pytest.mark.timeout(120)
@pytest.mark.timeout_unless_on_windows(120)
def test_grains_remove_add(
salt_call_cli, append_grain, wait_for_pillar_refresh_complete
):

View file

@ -135,7 +135,7 @@ def test_ssh_disabled(client, auth_creds):
assert ret is None
@pytest.mark.timeout(120)
@pytest.mark.timeout_unless_on_windows(120)
def test_shell_inject_ssh_priv(
client, salt_ssh_roster_file, rosters_dir, tmp_path, salt_auto_account
):

View file

@ -104,7 +104,7 @@ def test_reactor_reaction(
@pytest.mark.skip_on_windows(reason=PRE_PYTEST_SKIP_REASON)
@pytest.mark.timeout(120)
@pytest.mark.timeout_unless_on_windows(120)
def test_reactor_is_leader(
event_listener,
salt_master,

View file

@ -145,7 +145,7 @@ class TestGitBase(TestCase, AdaptedConfigurationTestCaseMixin):
provider._master_lock.release()
@pytest.mark.slow_test
@pytest.mark.timeout(120)
@pytest.mark.timeout_unless_on_windows(120)
def test_git_provider_mp_lock_timeout(self):
"""
Check that lock will time out if master lock is locked.
@ -160,7 +160,7 @@ class TestGitBase(TestCase, AdaptedConfigurationTestCaseMixin):
provider._master_lock.release()
@pytest.mark.slow_test
@pytest.mark.timeout(120)
@pytest.mark.timeout_unless_on_windows(120)
def test_git_provider_mp_clear_lock_timeout(self):
"""
Check that clear lock will time out if master lock is locked.