Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 765e08e

Browse files
committed
TST: use pytest name in naming files for check_figures_equal
If you stacked `pytest.mark.parametrize` with check_figures_equal every pass through would write to the same files. This: - add a pytest_pyfunc_call implementation hook to monkey-patch the test name onto the function - has the wrapper function check for the monkey-patched name and use that for the base file name
1 parent dbc35a9 commit 765e08e

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

lib/matplotlib/testing/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ def pytest_unconfigure(config):
2929
matplotlib._called_from_pytest = False
3030

3131

32+
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
33+
def pytest_pyfunc_call(pyfuncitem):
34+
item = pyfuncitem
35+
item.function._item_name_ = item.name
36+
yield
37+
38+
3239
@pytest.fixture(autouse=True)
3340
def mpl_test_settings(request):
3441
from matplotlib.testing.decorators import _cleanup_cm

lib/matplotlib/testing/decorators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,14 +389,14 @@ def decorator(func):
389389

390390
@pytest.mark.parametrize("ext", extensions)
391391
def wrapper(*args, ext, **kwargs):
392+
fn = getattr(wrapper, "_item_name_", func.__name__)
393+
392394
try:
393395
fig_test = plt.figure("test")
394396
fig_ref = plt.figure("reference")
395397
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-
)
398+
test_image_path = result_dir / (fn + "." + ext)
399+
ref_image_path = result_dir / (fn + "-expected." + ext)
400400
fig_test.savefig(test_image_path)
401401
fig_ref.savefig(ref_image_path)
402402
_raise_on_image_difference(

lib/matplotlib/tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from matplotlib.testing.conftest import (mpl_test_settings,
22
mpl_image_comparison_parameters,
33
pytest_configure, pytest_unconfigure,
4-
pd)
4+
pd, pytest_pyfunc_call)

0 commit comments

Comments
 (0)