-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_notebooks.py
More file actions
47 lines (34 loc) · 1.33 KB
/
test_notebooks.py
File metadata and controls
47 lines (34 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""test execution of notebooks in the repository"""
import gc
import os
import sys
import warnings
import nbformat
import pytest
from hooks.utils import find_files
if sys.platform == "win32" and sys.version_info[:2] >= (3, 7):
import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
with warnings.catch_warnings():
warnings.filterwarnings("ignore")
from nbconvert.preprocessors import ExecutePreprocessor
@pytest.fixture(
params=find_files(file_extension=".ipynb"),
name="notebook_filename",
)
def _notebook_filename(request):
return request.param
def test_run_notebooks(notebook_filename, tmp_path):
"""executes a given notebook"""
os.environ["JUPYTER_PLATFORM_DIRS"] = "1"
executor = ExecutePreprocessor(timeout=15 * 60, kernel_name="python3")
with open(notebook_filename, encoding="utf8") as notebook_file:
# https://github.com/pytest-dev/pytest-asyncio/issues/212
with warnings.catch_warnings():
warnings.filterwarnings("ignore", message="There is no current event loop")
executor.preprocess(
nbformat.read(notebook_file, as_version=4),
{"metadata": {"path": tmp_path}},
)
# so that nbconvert perplexities are reported here, and not at some dtor test later on
gc.collect()