Skip to content

Commit 8471a43

Browse files
committed
send executed notebook output to temp file, do not track .pytest-cache
1 parent 2019825 commit 8471a43

File tree

7 files changed

+52
-69
lines changed

7 files changed

+52
-69
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ target/
7373
# pyenv
7474
.python-version
7575

76+
# pytest
77+
.pytest_cache/
78+
7679
# celery beat schedule file
7780
celerybeat-schedule
7881

jupyter-notebooks/coverage/calculate_coverage.ipynb

Lines changed: 30 additions & 53 deletions
Large diffs are not rendered by default.

jupyter-notebooks/crop-classification/datasets-identify.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@
758758
"name": "python",
759759
"nbconvert_exporter": "python",
760760
"pygments_lexer": "ipython2",
761-
"version": "2.7.13"
761+
"version": "2.7.14"
762762
}
763763
},
764764
"nbformat": 4,

jupyter-notebooks/crop-classification/datasets-prepare.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@
742742
"name": "python",
743743
"nbconvert_exporter": "python",
744744
"pygments_lexer": "ipython2",
745-
"version": "2.7.13"
745+
"version": "2.7.14"
746746
}
747747
},
748748
"nbformat": 4,

jupyter-notebooks/crop-classification/segment-knn-tuning.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@
295295
"name": "python",
296296
"nbconvert_exporter": "python",
297297
"pygments_lexer": "ipython2",
298-
"version": "2.7.13"
298+
"version": "2.7.14"
299299
}
300300
},
301301
"nbformat": 4,

jupyter-notebooks/crop-classification/segment-knn.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1551,7 +1551,7 @@
15511551
"name": "python",
15521552
"nbconvert_exporter": "python",
15531553
"pygments_lexer": "ipython2",
1554-
"version": "2.7.13"
1554+
"version": "2.7.14"
15551555
}
15561556
},
15571557
"nbformat": 4,

tests/test_notebooks.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1+
"""
2+
Run each notebook in the jupyter-notebooks directory.
3+
4+
Notebooks are run using nbconvert.
5+
6+
pytest runs each test as a unit test.
7+
"""
18
import os
29
import subprocess
10+
import tempfile
311

4-
# import nbformat
5-
# from nbconvert.preprocessors import ExecutePreprocessor
612
import pytest
713

14+
NOTEBOOK_EXT = '.ipynb'
815
ROOT_DIR = '.'
916

1017

1118
def find_notebooks(root_dir):
12-
print(os.listdir(root_dir))
13-
notebook_ext = '.ipynb'
14-
1519
notebooks = []
1620
for (dirpath, dirnames, filenames) in os.walk(root_dir):
1721
# look for 'norun' file, if present, do not look for notebooks in this dir
@@ -28,19 +32,18 @@ def find_notebooks(root_dir):
2832

2933
for name in filenames:
3034
ext = os.path.splitext(name)[1]
31-
if ext == notebook_ext:
35+
if ext == NOTEBOOK_EXT:
3236
# convert to string so test displays the path
3337
notebook_name = str(os.path.join(dirpath, name))
34-
print(notebook_name)
35-
print(type(notebook_name))
3638
notebooks.append(notebook_name)
3739

3840
return notebooks
3941

4042

4143
@pytest.mark.parametrize("notebook", find_notebooks(ROOT_DIR))
4244
def test_run_notebooks(notebook):
43-
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
44-
"--ExecutePreprocessor.timeout=600",
45-
notebook]
46-
subprocess.check_call(args)
45+
with tempfile.NamedTemporaryFile(suffix=NOTEBOOK_EXT) as tmp_nb:
46+
args = ["jupyter", "nbconvert", "--to", "notebook", "--execute",
47+
"--ExecutePreprocessor.timeout=600",
48+
notebook, "--output", tmp_nb.name]
49+
subprocess.check_call(args)

0 commit comments

Comments
 (0)