From fcc71031c31081705ef4a751e9043452cbea8368 Mon Sep 17 00:00:00 2001
From: Frederik Hennig <frederik.hennig@fau.de>
Date: Mon, 22 Jul 2024 13:04:39 +0200
Subject: [PATCH] Fix unclosed matplotlib figures:

 - Notebook tests used to leave their figures open, which increases memory consumption; also, auto-closing before backend change is now deprecated in matplotlib.
---
 conftest.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/conftest.py b/conftest.py
index 5ae7aacb..c989bd81 100644
--- a/conftest.py
+++ b/conftest.py
@@ -111,14 +111,20 @@ 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
+        # Also animations cannot be shown, which also leads to a warning.
         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.*');"
+             "warnings.filterwarnings('ignore', 'Animation was deleted without rendering anything.*');",
              global_dict)
         with tempfile.NamedTemporaryFile() as f:
             f.write(self.code.encode())
             f.flush()
             runpy.run_path(f.name, init_globals=global_dict, run_name=self.name)
 
+        #   Close any open figures
+        exec("import matplotlib.pyplot as p; "
+             "p.close('all')", global_dict)
+
 
 class IPyNbFile(pytest.File):
     def collect(self):
-- 
GitLab