Skip to content

Commit

Permalink
update conftest
Browse files Browse the repository at this point in the history
  • Loading branch information
robsdavis committed Sep 10, 2024
1 parent 26e12ab commit 929541a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
17 changes: 15 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,32 @@

# 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


@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}")

0 comments on commit 929541a

Please sign in to comment.