Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4ddf004

Browse filesBrowse files
authored
Merge pull request #15589 from MarcoGorelli/close-plots-in-check-figures-equal
Make sure that figures are closed when check_figures_equal finishes
2 parents b733e5a + 7549874 commit 4ddf004
Copy full SHA for 4ddf004

File tree

Expand file treeCollapse file tree

1 file changed

+16
-12
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-12
lines changed

‎lib/matplotlib/testing/decorators.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/decorators.py
+16-12Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -389,18 +389,22 @@ def decorator(func):
389389

390390
@pytest.mark.parametrize("ext", extensions)
391391
def wrapper(*args, ext, **kwargs):
392-
fig_test = plt.figure("test")
393-
fig_ref = plt.figure("reference")
394-
func(*args, fig_test=fig_test, fig_ref=fig_ref, **kwargs)
395-
test_image_path = result_dir / (func.__name__ + "." + ext)
396-
ref_image_path = result_dir / (
397-
func.__name__ + "-expected." + ext
398-
)
399-
fig_test.savefig(test_image_path)
400-
fig_ref.savefig(ref_image_path)
401-
_raise_on_image_difference(
402-
ref_image_path, test_image_path, tol=tol
403-
)
392+
try:
393+
fig_test = plt.figure("test")
394+
fig_ref = plt.figure("reference")
395+
func(*args, fig_test=fig_test, fig_ref=fig_ref, **kwargs)
396+
test_image_path = result_dir / (func.__name__ + "." + ext)
397+
ref_image_path = result_dir / (
398+
func.__name__ + "-expected." + ext
399+
)
400+
fig_test.savefig(test_image_path)
401+
fig_ref.savefig(ref_image_path)
402+
_raise_on_image_difference(
403+
ref_image_path, test_image_path, tol=tol
404+
)
405+
finally:
406+
plt.close(fig_test)
407+
plt.close(fig_ref)
404408

405409
sig = inspect.signature(func)
406410
new_sig = sig.replace(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.