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 765e08e

Browse filesBrowse 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
Copy full SHA for 765e08e

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+12
-5
lines changed

‎lib/matplotlib/testing/conftest.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/conftest.py
+7Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/decorators.py
+4-4Lines 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

Copy file name to clipboard
+1-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.