Skip to content

Commit cc287af

Browse files
committed
example tests: remove checkpoints after test, minor adjustments
1 parent 9338b1b commit cc287af

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

tests/test_examples/test_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
from tests.utils import run_notebook
44

55

6+
@pytest.mark.skip(reason="requires setting up Stan")
67
@pytest.mark.slow
78
def test_bayesian_experimental_design(examples_path):
89
run_notebook(examples_path / "Bayesian_Experimental_Design.ipynb")
910

1011

11-
@pytest.mark.skip(reason="Requires setting up Stan.")
1212
@pytest.mark.slow
1313
def test_from_abc_to_bayesflow(examples_path):
1414
run_notebook(examples_path / "From_ABC_to_BayesFlow.ipynb")

tests/utils/jupyter.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,26 @@
22
from nbconvert.preprocessors import ExecutePreprocessor
33

44
from pathlib import Path
5+
import shutil
56

67

78
def run_notebook(path):
9+
path = Path(path)
10+
checkpoint_path = path.parent / "checkpoints"
11+
# only clean up if the directory did not exist before the test
12+
cleanup_checkpoints = not checkpoint_path.exists()
813
with open(str(path)) as f:
914
nb = nbformat.read(f, nbformat.NO_CONVERT)
1015

11-
kernel = ExecutePreprocessor(
12-
timeout=600, kernel_name="python3", resources={"metadata": {"path": Path(path).parent}}
13-
)
16+
kernel = ExecutePreprocessor(timeout=600, kernel_name="python3", resources={"metadata": {"path": path.parent}})
17+
18+
try:
19+
result = kernel.preprocess(nb)
20+
except Exception as e:
21+
raise e
22+
finally:
23+
if cleanup_checkpoints and checkpoint_path.exists():
24+
# clean up if the directory was created by the test
25+
shutil.rmtree(checkpoint_path)
1426

15-
result = kernel.preprocess(nb)
1627
return result

0 commit comments

Comments
 (0)