Skip to content

Commit cab2a30

Browse files
committed
ENH: add pytest flag + restore default values via ENV
1 parent 74f69b8 commit cab2a30

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ class _ImageComparisonBase:
122122
This class provides *just* the comparison-related functionality and avoids
123123
any code that would be specific to any testing framework.
124124
"""
125-
def __init__(self, func, tol, remove_text, savefig_kwargs):
125+
def __init__(self, func, tol, remove_text, savefig_kwargs, external_images):
126126
self.func = func
127127
self.result_dir = _results_directory(func)
128+
print(external_images)
128129
(self.root_dir, mod_dir, image_list, self.md_path) = _baseline_directory(
129-
func, os.environ.get("MPLTESTIMAGEPATH", None)
130+
func, external_images
130131
)
131132
self.image_revs = _load_blame(image_list)
132133
self.baseline_dir = self.root_dir / mod_dir
@@ -293,8 +294,11 @@ def wrapper(*args, extension, request, **kwargs):
293294
}.get(extension, 'on this system')
294295
pytest.skip(f"Cannot compare {extension} files {reason}")
295296

296-
img = _ImageComparisonBase(func, tol=tol, remove_text=remove_text,
297-
savefig_kwargs=savefig_kwargs)
297+
img = _ImageComparisonBase(
298+
func,
299+
tol=tol, remove_text=remove_text, savefig_kwargs=savefig_kwargs,
300+
external_images=request.config.getoption("--image-baseline")
301+
)
298302
matplotlib.testing.set_font_settings_for_testing()
299303

300304
with _collect_new_figures() as figs:

lib/matplotlib/testing/generate_images_plugin.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import pytest
2+
import os
23

34

45
def pytest_addoption(parser):
56
parser.addoption(
67
"--generate-images",
78
action="store_true",
8-
default=False,
9+
default=bool(os.environ.get('MPLGENERATEBASELINE', False)),
910
help="run matplotlib baseline image generation tests"
1011
)
12+
parser.addoption(
13+
"--image-baseline",
14+
default=os.environ.get('MPLBASELINEIMAGES', None),
15+
help="run matplotlib baseline image generation tests",
16+
type=str
17+
)
1118

1219

1320
def pytest_collection_modifyitems(config, items):

0 commit comments

Comments
 (0)