8
8
import sys
9
9
import unittest
10
10
import warnings
11
+ import string
11
12
12
13
import matplotlib as mpl
13
14
import matplotlib .style
17
18
from matplotlib import ft2font
18
19
from matplotlib import pyplot as plt
19
20
from matplotlib import ticker
20
- from . import is_called_from_pytest
21
+
21
22
from .compare import comparable_formats , compare_images , make_test_filename
22
23
from .exceptions import ImageComparisonFailure
23
24
@@ -381,22 +382,23 @@ def test_plot(fig_test, fig_ref):
381
382
fig_test.subplots().plot([1, 3, 5])
382
383
fig_ref.subplots().plot([0, 1, 2], [1, 3, 5])
383
384
"""
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
385
387
def decorator (func ):
386
388
import pytest
387
389
388
390
_ , result_dir = _image_directories (func )
389
391
390
392
@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 )
392
396
try :
393
397
fig_test = plt .figure ("test" )
394
398
fig_ref = plt .figure ("reference" )
395
399
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 )
400
402
fig_test .savefig (test_image_path )
401
403
fig_ref .savefig (ref_image_path )
402
404
_raise_on_image_difference (
@@ -411,7 +413,10 @@ def wrapper(*args, ext, **kwargs):
411
413
parameters = ([param
412
414
for param in sig .parameters .values ()
413
415
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
+ ])
415
420
)
416
421
wrapper .__signature__ = new_sig
417
422
0 commit comments