Skip to content

Commit cac3187

Browse files
committed
Revert "Use pytest_notebook to test whether notebooks run without errors"
This reverts commit 07649a9.
1 parent 9aec02e commit cac3187

File tree

2 files changed

+40
-15
lines changed

2 files changed

+40
-15
lines changed

example/test_examples.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
"""
55

66
import os
7+
import subprocess
8+
import tempfile
9+
import nbformat
10+
import sys
711
from example import modelchain_example as mc_e
812
from example import turbine_cluster_modelchain_example as tc_mc_e
913
from numpy.testing import assert_allclose
10-
import pytest_notebook
14+
import pytest
1115

1216

1317
class TestExamples:
@@ -53,29 +57,50 @@ def test_turbine_cluster_modelchain_example_flh(self):
5357

5458
def _notebook_run(self, path):
5559
"""
56-
Execute a notebook and collect output.
60+
Execute a notebook via nbconvert and collect output.
5761
Returns (parsed nb object, execution errors)
5862
"""
59-
dirname, nb_name = os.path.split(path)
63+
dirname, __ = os.path.split(path)
6064
os.chdir(dirname)
61-
notebook = pytest_notebook.notebook.load_notebook(path=nb_name)
62-
result = pytest_notebook.execution.execute_notebook(
63-
notebook,
64-
with_coverage=False,
65-
timeout=600,
66-
)
67-
return result.exec_error
65+
with tempfile.NamedTemporaryFile(suffix=".ipynb") as fout:
66+
args = [
67+
"jupyter",
68+
"nbconvert",
69+
"--to",
70+
"notebook",
71+
"--execute",
72+
"--ExecutePreprocessor.timeout=60",
73+
"--output",
74+
fout.name,
75+
path,
76+
]
77+
subprocess.check_call(args)
78+
79+
fout.seek(0)
80+
nb = nbformat.read(fout, nbformat.current_nbformat)
81+
82+
errors = [
83+
output
84+
for cell in nb.cells
85+
if "outputs" in cell
86+
for output in cell["outputs"]
87+
if output.output_type == "error"
88+
]
89+
90+
return nb, errors
6891

92+
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6")
6993
def test_modelchain_example_ipynb(self):
7094
dir_path = os.path.dirname(os.path.realpath(__file__))
71-
errors = self._notebook_run(
95+
nb, errors = self._notebook_run(
7296
os.path.join(dir_path, "modelchain_example.ipynb")
7397
)
74-
assert errors is None
98+
assert errors == []
7599

100+
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires python3.6")
76101
def test_turbine_cluster_modelchain_example_ipynb(self):
77102
dir_path = os.path.dirname(os.path.realpath(__file__))
78-
errors = self._notebook_run(
103+
nb, errors = self._notebook_run(
79104
os.path.join(dir_path, "turbine_cluster_modelchain_example.ipynb")
80105
)
81-
assert errors is None
106+
assert errors == []

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def read(fname):
3030
"pytest",
3131
"jupyter",
3232
"sphinx_rtd_theme",
33+
"nbformat",
3334
"numpy",
3435
"matplotlib",
35-
"pytest-notebook",
3636
]
3737
},
3838
)

0 commit comments

Comments
 (0)