From 914d436ce9678ef5f2ae0dbdc0d08fa91c9b14ff Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Fri, 19 Jan 2024 12:30:24 +0000 Subject: [PATCH] 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 --- tests/conftest.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index f0d8d71b496f..c6d51f6df557 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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