Timeout all unit tests at 60 seconds(if not running on windows)

We have some random test hangs and this will prevent that by forcing the
tests to fail in such cases.
Windows does not take part of this because it does not support
`signal.SIGABRT`, we would have to use threads.

Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
Pedro Algarvio 2024-01-19 12:30:24 +00:00 committed by Pedro Algarvio
parent 4907eb2a8c
commit 7d6a97e7ba

View file

@ -445,7 +445,22 @@ def pytest_collection_modifyitems(config, items):
from_filenames_collection_modifyitems(config, items)
log.warning("Mofifying collected tests to keep track of fixture usage")
timeout_marker_tests_paths = (
str(TESTS_DIR / "unit"),
str(PYTESTS_DIR / "unit"),
)
for item in items:
if (
not salt.utils.platform.is_windows()
and 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