From d4ac8672402d31a4ddaae37cbfc215af54a39440 Mon Sep 17 00:00:00 2001
From: Martin Bauer <martin.bauer@fau.de>
Date: Tue, 3 Dec 2019 15:19:55 +0100
Subject: [PATCH] tests: suppress warnings from jupyter notebook runner

---
 conftest.py | 12 ++++++++----
 pytest.ini  |  4 ++++
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/conftest.py b/conftest.py
index 05007fb..743b356 100644
--- a/conftest.py
+++ b/conftest.py
@@ -3,6 +3,7 @@ import pytest
 import tempfile
 import runpy
 import sys
+import warnings
 # Trigger config file reading / creation once - to avoid race conditions when multiple instances are creating it
 # at the same time
 from pystencils.cpu import cpujit
@@ -89,7 +90,7 @@ class IPyNbTest(pytest.Item):
         # in notebooks there is an implicit plt.show() - if this is not called a warning is shown when the next
         # plot is created. This warning is suppressed here
         exec("import warnings;"
-             "warnings.filterwarnings('ignore', 'Adding an axes using the same arguments as a previous.*')",
+             "warnings.filterwarnings('ignore', 'Adding an axes using the same arguments as a previous.*');",
              global_dict)
         with tempfile.NamedTemporaryFile() as f:
             f.write(self.code.encode())
@@ -104,9 +105,12 @@ class IPyNbFile(pytest.File):
         exporter.exclude_input_prompt = True
 
         notebook_contents = self.fspath.open()
-        notebook = nbformat.read(notebook_contents, 4)
-        code, _ = exporter.from_notebook_node(notebook)
-        yield IPyNbTest(self.name, self, code)
+
+        with warnings.catch_warnings():
+            warnings.filterwarnings("ignore", "IPython.core.inputsplitter is deprecated")
+            notebook = nbformat.read(notebook_contents, 4)
+            code, _ = exporter.from_notebook_node(notebook)
+            yield IPyNbTest(self.name, self, code)
 
     def teardown(self):
         pass
diff --git a/pytest.ini b/pytest.ini
index d45acff..b41ca68 100644
--- a/pytest.ini
+++ b/pytest.ini
@@ -2,6 +2,10 @@
 python_files = test_*.py *_test.py scenario_*.py
 norecursedirs = *.egg-info .git .cache .ipynb_checkpoints htmlcov
 addopts = --doctest-modules --durations=20  --cov-config pytest.ini
+markers =
+       longrun: tests only run at night since they have large execution time
+       notebook: jupyter notebooks
+
 
 [run]
 branch = True
-- 
GitLab