Skip to content

Commit

Permalink
Merge pull request #169 from jhlegarreta/UseAFixtureToCloseMplFigs
Browse files Browse the repository at this point in the history
ENH: Use a fixture to close `Matplotlib` figures in tests
  • Loading branch information
effigies authored Feb 16, 2025
2 parents 8a69b48 + 1973f60 commit 7320552
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 8 additions & 0 deletions nireports/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import os

import matplotlib.pyplot as plt
import pytest
from templateflow.api import get as get_template

Expand Down Expand Up @@ -57,3 +58,10 @@ def nthreads():

# Tests are linear, so don't worry about leaving space for a control thread
return min(int(getenv("CIRCLE_NPROCS", "8")), cpu_count())


@pytest.fixture(autouse=True)
def close_mpl_figures():
"""Automatically close all Matplotlib figures after each test."""
yield
plt.close("all")
7 changes: 0 additions & 7 deletions nireports/tests/test_reportlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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
Expand Down Expand Up @@ -130,8 +129,6 @@ def test_carpetplot(tr, sorting, outdir):
sort_rows=sorting,
)

plt.close("all")


@pytest.mark.parametrize(
"input_files",
Expand Down Expand Up @@ -320,8 +317,6 @@ def test_cifti_carpetplot(tmp_path, test_data_package, outdir):
cmap="paired",
)

plt.close("all")


def test_nifti_carpetplot(tmp_path, test_data_package, outdir):
"""Exercise extraction of timeseries from CIFTI2."""
Expand All @@ -343,8 +338,6 @@ def test_nifti_carpetplot(tmp_path, test_data_package, outdir):
drop_trs=0,
)

plt.close("all")


_views = list(permutations(("axial", "sagittal", "coronal", None), 3)) + [
(v, None, None) for v in ("axial", "sagittal", "coronal")
Expand Down

0 comments on commit 7320552

Please sign in to comment.