diff --git a/.github/workflows/test_pr.yml b/.github/workflows/test_pr.yml index af65d577..9ff1da10 100644 --- a/.github/workflows/test_pr.yml +++ b/.github/workflows/test_pr.yml @@ -72,7 +72,7 @@ jobs: run: | pip install .[testing] pip freeze - pytest -vvvsx --timeout=300 --timeout-nofail --timeout-method=thread -m "not slow" --durations=50 + pytest -vvvsx --timeout=300 --timeout-method=thread -m "not slow" --durations=50 - name: Test GOGGLE run: | pip install .[testing,goggle] diff --git a/tests/conftest.py b/tests/conftest.py index 3b02b350..3ec94e64 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,8 @@ # third party import pytest +from _pytest.nodes import Item +from _pytest.runner import CallInfo # synthcity absolute from synthcity.utils.reproducibility import clear_cache, enable_reproducible_results @@ -12,12 +14,23 @@ @pytest.fixture(autouse=True, scope="session") def run_before_tests() -> Generator: + """Setup reproducible results and clear cache before tests.""" enable_reproducible_results(0) clear_cache() yield - # cleanup after test + # Cleanup after tests workspace = Path("workspace") - if workspace.exists(): + if workspace.exists() and workspace.is_dir(): shutil.rmtree(workspace, ignore_errors=True) + + +# Hook to modify the test result if it exceeds a timeout +def pytest_runtest_makereport(item: Item, call: CallInfo) -> None: + """Modify the test result if it exceeds the timeout to skip instead of failing.""" + if call.when == "call" and call.excinfo is not None: + # Check if the exception is a TimeoutError from pytest-timeout + if isinstance(call.excinfo.value, pytest.TimeoutExpired): + # Mark the test as skipped due to exceeding the timeout + pytest.skip(f"Test skipped due to exceeding the timeout: {item.nodeid}")