From 2358cfcb4e18dc236de6d1befb244f16d4290721 Mon Sep 17 00:00:00 2001 From: Sylwester Arabas Date: Sun, 30 Jul 2023 15:08:54 +0200 Subject: [PATCH] add test checking if no error messages are left in notebook output (#19) * add test checking if no error messages are left in notebook output. closes #12 * pylint and precommit fixes --- test_notebooks.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test_notebooks.py b/test_notebooks.py index 74588f7..20b4ed8 100644 --- a/test_notebooks.py +++ b/test_notebooks.py @@ -58,3 +58,15 @@ def test_run_notebooks(notebook_filename, tmp_path): def test_file_size(notebook_filename): """checks if all example Jupyter notebooks have file size less than a certain limit""" assert os.stat(notebook_filename).st_size * SI.byte < 1 * SI.megabyte + + +def test_no_errors_or_warnings_in_output(notebook_filename): + """checks if all example Jupyter notebooks have clear std-err output + (i.e., no errors or warnings) visible""" + with open(notebook_filename, encoding="utf8") as notebook_file: + notebook = nbformat.read(notebook_file, nbformat.NO_CONVERT) + for cell in notebook.cells: + if cell.cell_type == "code": + for output in cell.outputs: + if "name" in output and output["name"] == "stderr": + raise AssertionError(output["text"])