From 260a8b9fcc0e1f888dbad110e3c49b5f10f2fb3e Mon Sep 17 00:00:00 2001 From: Brett Date: Fri, 20 Sep 2024 11:42:56 -0400 Subject: [PATCH] put slow tests first --- jwst/conftest.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/jwst/conftest.py b/jwst/conftest.py index e46d8f335ec..576f2dc91bd 100644 --- a/jwst/conftest.py +++ b/jwst/conftest.py @@ -9,6 +9,39 @@ from jwst.associations.tests.helpers import t_path +# slow test modules (and an example runtime for their slowest test) +# the runtime is likely dominated by a fixutre reused for tests in that module +_SLOW_TEST_MODULES = [ + 'jwst.regtest.test_nirspec_ifu_spec3_pixelreplace', # 4213 seconds + 'jwst.regtest.test_nirspec_ifu_spec3', # 3698 seconds + 'jwst.regtest.test_nirspec_ifu_spec3_emsm', # 3129 seconds + 'jwst.regtest.test_niriss_soss', # 2739 seconds + 'jwst.regtest.test_nirspec_ifu_spec2', # 1382 seconds + 'jwst.regtest.test_nrispec_lamp_ifu_spec2', # 847 seconds + 'jwst.regtest.test_nirspec_steps_spec2', # 710 seconds +] + + +def _get_test_item_module_name(item): + if not hasattr(item, 'module'): + return None + return item.module.__name__ + + +@pytest.hookimpl(trylast=True) +def pytest_collection_modifyitems(config, items): + # reorder tests to put known slow ones first, this helps + # to prevent slow tests from starting later in the test run + for (i, module_name) in enumerate(_SLOW_TEST_MODULES): + if _get_test_item_module_name(items[i]) != module_name: + # swap this with a later test not in a slow module + for j in range(i, len(items)): + if _get_test_item_module_name(items[j]) == module_name: + items[i], items[j] = items[j], items[i] + break + return items + + @pytest.fixture def jail_environ(): """Lock changes to the environment"""