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
@@ -382,22 +383,23 @@ def test_plot(fig_test, fig_ref):
382
383
fig_test.subplots().plot([1, 3, 5])
383
384
fig_ref.subplots().plot([0, 1, 2], [1, 3, 5])
384
385
"""
385
- POSITIONAL_OR_KEYWORD = inspect .Parameter .POSITIONAL_OR_KEYWORD
386
+ ALLOWED_CHARS = set (string .digits + string .ascii_letters + '_-[]()' )
387
+ KEYWORD_ONLY = inspect .Parameter .KEYWORD_ONLY
386
388
def decorator (func ):
387
389
import pytest
388
390
389
391
_ , result_dir = _image_directories (func )
390
392
391
393
@pytest .mark .parametrize ("ext" , extensions )
392
- def wrapper (* args , ext , ** kwargs ):
394
+ def wrapper (* args , ext , request , ** kwargs ):
395
+ file_name = "" .join (c for c in request .node .name
396
+ if c in ALLOWED_CHARS )
393
397
try :
394
398
fig_test = plt .figure ("test" )
395
399
fig_ref = plt .figure ("reference" )
396
400
func (* args , fig_test = fig_test , fig_ref = fig_ref , ** kwargs )
397
- test_image_path = result_dir / (func .__name__ + "." + ext )
398
- ref_image_path = result_dir / (
399
- func .__name__ + "-expected." + ext
400
- )
401
+ test_image_path = result_dir / (file_name + "." + ext )
402
+ ref_image_path = result_dir / (file_name + "-expected." + ext )
401
403
fig_test .savefig (test_image_path )
402
404
fig_ref .savefig (ref_image_path )
403
405
_raise_on_image_difference (
@@ -412,7 +414,10 @@ def wrapper(*args, ext, **kwargs):
412
414
parameters = ([param
413
415
for param in sig .parameters .values ()
414
416
if param .name not in {"fig_test" , "fig_ref" }]
415
- + [inspect .Parameter ("ext" , POSITIONAL_OR_KEYWORD )])
417
+ + [
418
+ inspect .Parameter ("ext" , KEYWORD_ONLY ),
419
+ inspect .Parameter ("request" , KEYWORD_ONLY ),
420
+ ])
416
421
)
417
422
wrapper .__signature__ = new_sig
418
423
0 commit comments