From 72b28a56d6a2abda07cf936be0c127c43b286047 Mon Sep 17 00:00:00 2001
From: Eleni Mathioulaki <emathioulaki@athenarc.gr>
Date: Sat, 21 Oct 2023 02:25:01 +0200
Subject: [PATCH] set cell timeout to prevent tests from hanging

---
 packages/wf-brainscales2-demos/package.py | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/packages/wf-brainscales2-demos/package.py b/packages/wf-brainscales2-demos/package.py
index 59c505af..580fd5ce 100644
--- a/packages/wf-brainscales2-demos/package.py
+++ b/packages/wf-brainscales2-demos/package.py
@@ -44,6 +44,7 @@ class WfBrainscales2Demos(Package):
         args = [
             "nbconvert",
             "--ExecutePreprocessor.kernel_name=python3",
+            "--ExecutePreprocessor.timeout=900",
             "--execute",
             "--to",
             "notebook",
@@ -53,16 +54,25 @@ class WfBrainscales2Demos(Package):
         ]
         try:
             # execute notebook and save
-            jupyter(*args)
+            jupyter(*args, output=str.split, error=str.split)
         except ProcessError as e:
-            # if the above fails, re-run notebook to produce output with error
-            jupyter(*(args+["--allow-errors"]))
+            # if the notebook execution fails, re-run notebook to produce output with error
+            # in case of a cell timeout, don't re-run
+            if "CellTimeoutError" not in e:
+                jupyter(*(args+["--allow-errors"]))
             raise
 
     def _run_notebooks(self, output_dir):
         mkdirp(output_dir)
+        # try to run all notebooks, then fail if there are errors
+        exceptions = []
         for fn in glob(join_path(prefix, "notebooks", "ts*.ipynb")) + glob(join_path(prefix, "notebooks", "tp*.ipynb")):
-            self._nbconvert(fn, join_path(output_dir, os.path.basename(fn)))
+            try:
+                self._nbconvert(fn, join_path(output_dir, os.path.basename(fn)))
+            except Exception as e:
+                exceptions.append(e)
+        if exceptions:
+            raise Exception("Errors during notebook execution")
 
     def _set_collab_things(self):
         # enable "EBRAINS lab" mode
-- 
GitLab