Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 28e32c6

Browse filesBrowse files
authored
Merge pull request #14157 from anntzer/nbaggtest
TST: Isolate nbagg test from user ipython profile.
2 parents af33de4 + f9e1617 commit 28e32c6
Copy full SHA for 28e32c6

File tree

Expand file treeCollapse file tree

1 file changed

+15
-19
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-19
lines changed
+15-19Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import os
12
from pathlib import Path
23
import subprocess
3-
import tempfile
4+
from tempfile import TemporaryDirectory
45

56
import pytest
67

@@ -9,25 +10,20 @@
910
# From https://blog.thedataincubator.com/2016/06/testing-jupyter-notebooks/
1011

1112

12-
def _notebook_run(nb_file):
13-
"""Execute a notebook via nbconvert and collect output.
14-
:returns (parsed nb object, execution errors)
15-
"""
16-
with tempfile.NamedTemporaryFile(suffix=".ipynb", mode='w+t') as fout:
17-
subprocess.check_call([
18-
"jupyter", "nbconvert", "--to", "notebook",
19-
"--execute", "--ExecutePreprocessor.timeout=500",
20-
"--output", fout.name, nb_file,
21-
])
22-
fout.seek(0)
23-
nb = nbformat.read(fout, nbformat.current_nbformat)
13+
def test_ipynb():
14+
nb_path = Path(__file__).parent / 'test_nbagg_01.ipynb'
15+
16+
with TemporaryDirectory() as tmpdir:
17+
out_path = Path(tmpdir, "out.ipynb")
18+
subprocess.check_call(
19+
["jupyter", "nbconvert", "--to", "notebook",
20+
"--execute", "--ExecutePreprocessor.timeout=500",
21+
"--output", str(out_path), str(nb_path)],
22+
env={**os.environ, "IPYTHONDIR": tmpdir})
23+
with out_path.open() as out:
24+
nb = nbformat.read(out, nbformat.current_nbformat)
2425

2526
errors = [output for cell in nb.cells if "outputs" in cell
2627
for output in cell["outputs"]
2728
if output.output_type == "error"]
28-
return nb, errors
29-
30-
31-
def test_ipynb():
32-
nb, errors = _notebook_run(Path(__file__).parent / 'test_nbagg_01.ipynb')
33-
assert errors == []
29+
assert not errors

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.