Skip to content

Commit

Permalink
Merge: Use Subprocess Runs for Example Tests (#327)
Browse files Browse the repository at this point in the history
`runpy` did not run example files in isolated environments, causing
problems with examples that had hook modifications via monkeypatching.
`subprocess.run` calls a separate process hence not exhibiting the
problem

this also required some coverage exceptions as some utils are only
tested in examples
  • Loading branch information
Scienfitz authored Jul 31, 2024
2 parents ebb17d9 + 14f3921 commit 31c6804
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[run]
omit =
[report]
omit =
baybe/utils/plotting.py
baybe/utils/random.py
baybe/utils/botorch_wrapper.py
baybe/simulation/*
11 changes: 8 additions & 3 deletions tests/docs/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Test if all examples can be run without error."""

import os
import runpy
import subprocess
from pathlib import Path

import pytest
Expand All @@ -22,8 +22,13 @@
)
@pytest.mark.parametrize("example", paths, ids=paths)
def test_example(example: str):
"""Test an individual example by running it."""
runpy.run_path(example)
"""Test an individual example by running it.
This runs in a separate process and isolated environment due to problems caused by
monkeypatching in some examples affecting other tests if they were executed in the
same environment.
"""
subprocess.run(["python", example], check=True)


if _SMOKE_TEST_CACHE is not None:
Expand Down

0 comments on commit 31c6804

Please sign in to comment.