Skip to content

Commit 3d9b7dc

Browse files
committed
Merge pull request #16693 from tacaswell/tst_better_compare_names
TST: use pytest name in naming files for check_figures_equal
1 parent 9211537 commit 3d9b7dc

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import os
66
from pathlib import Path
77
import shutil
8+
import string
89
import sys
910
import unittest
1011
import warnings
@@ -17,7 +18,7 @@
1718
from matplotlib import ft2font
1819
from matplotlib import pyplot as plt
1920
from matplotlib import ticker
20-
from . import is_called_from_pytest
21+
2122
from .compare import comparable_formats, compare_images, make_test_filename
2223
from .exceptions import ImageComparisonFailure
2324

@@ -381,22 +382,23 @@ def test_plot(fig_test, fig_ref):
381382
fig_test.subplots().plot([1, 3, 5])
382383
fig_ref.subplots().plot([0, 1, 2], [1, 3, 5])
383384
"""
384-
POSITIONAL_OR_KEYWORD = inspect.Parameter.POSITIONAL_OR_KEYWORD
385+
ALLOWED_CHARS = set(string.digits + string.ascii_letters + '_-[]()')
386+
KEYWORD_ONLY = inspect.Parameter.KEYWORD_ONLY
385387
def decorator(func):
386388
import pytest
387389

388390
_, result_dir = _image_directories(func)
389391

390392
@pytest.mark.parametrize("ext", extensions)
391-
def wrapper(*args, ext, **kwargs):
393+
def wrapper(*args, ext, request, **kwargs):
394+
file_name = "".join(c for c in request.node.name
395+
if c in ALLOWED_CHARS)
392396
try:
393397
fig_test = plt.figure("test")
394398
fig_ref = plt.figure("reference")
395399
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+
test_image_path = result_dir / (file_name + "." + ext)
401+
ref_image_path = result_dir / (file_name + "-expected." + ext)
400402
fig_test.savefig(test_image_path)
401403
fig_ref.savefig(ref_image_path)
402404
_raise_on_image_difference(
@@ -411,7 +413,10 @@ def wrapper(*args, ext, **kwargs):
411413
parameters=([param
412414
for param in sig.parameters.values()
413415
if param.name not in {"fig_test", "fig_ref"}]
414-
+ [inspect.Parameter("ext", POSITIONAL_OR_KEYWORD)])
416+
+ [
417+
inspect.Parameter("ext", KEYWORD_ONLY),
418+
inspect.Parameter("request", KEYWORD_ONLY),
419+
])
415420
)
416421
wrapper.__signature__ = new_sig
417422

0 commit comments

Comments
 (0)