Skip to content

Commit f2468c7

Browse files
committed
Remove unused plt.show and ensure matplotlib figures are closed
Removed an unnecessary `plt.show()` call in the test to streamline the code. Added a `pytest_runtest_teardown` hook to automatically close all matplotlib figures after tests to prevent resource leaks and improve test isolation.
1 parent c0a4f25 commit f2468c7

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

tests/test_diagnostics/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
from bayesflow.utils.numpy_utils import softmax
55

66

7+
def pytest_runtest_teardown(item, nextitem):
8+
import matplotlib.pyplot as plt
9+
10+
plt.close("all")
11+
12+
713
@pytest.fixture()
814
def var_names():
915
return [r"$\beta_0$", r"$\beta_1$", r"$\sigma$"]

tests/test_diagnostics/test_diagnostics_plots.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ def test_calibration_histogram(random_estimates, random_targets):
4646

4747

4848
def test_loss(history):
49-
import matplotlib.pyplot as plt
50-
5149
out = bf.diagnostics.loss(history)
52-
plt.show()
5350
assert len(out.axes) == 1
5451
assert out.axes[0].title._text == "Loss Trajectory"
5552

0 commit comments

Comments
 (0)