From 626dd354f0d7c79c2f5c4cd98ec4534481deb5bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Wed, 8 Jan 2025 20:12:56 -0500 Subject: [PATCH] ENH: Close figures in test explicitly Close figures in test explicitly: when the `output_file` argument is `None` the `plot_carpet` method does not close figures, and thus a warning is raised if the number of open figures exceeds a given value. Fixes: ``` nireports/tests/test_reportlets.py::test_carpetplot[linkage-0.7] /home/runner/work/nireports/nireports/nireports/reportlets/nuisance.py:326: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). Consider using `matplotlib.pyplot.close()`. figure, allaxes = plt.subplots(figsize=(19.2, 10)) ``` reported for example in: https://github.com/nipreps/nireports/actions/runs/12681153218/job/35344304375#step:12:351 --- nireports/tests/test_reportlets.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nireports/tests/test_reportlets.py b/nireports/tests/test_reportlets.py index d1a32640..8095c612 100644 --- a/nireports/tests/test_reportlets.py +++ b/nireports/tests/test_reportlets.py @@ -27,6 +27,7 @@ from itertools import permutations from pathlib import Path +import matplotlib.pyplot as plt import nibabel as nb import numpy as np import pandas as pd @@ -127,6 +128,8 @@ def test_carpetplot(tr, sorting, outdir): sort_rows=sorting, ) + plt.close() + @pytest.mark.parametrize( "input_files",