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 224352a

Browse filesBrowse files
committed
Use skipif, not xfail, for uncomparable image formats.
1 parent 9332a06 commit 224352a
Copy full SHA for 224352a

File tree

Expand file treeCollapse file tree

2 files changed

+18
-20
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+18
-20
lines changed
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The image comparison test decorators now skip (rather than xfail) the test for uncomparable formats
2+
```````````````````````````````````````````````````````````````````````````````````````````````````
3+
4+
The affected decorators are `~.image_comparison` and `~.check_figures_equal`.
5+
The deprecated `~.ImageComparisonTest` class is likewise changed.

‎lib/matplotlib/testing/decorators.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/decorators.py
+13-20Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,37 +148,30 @@ def _raise_on_image_difference(expected, actual, tol):
148148
% err)
149149

150150

151-
def _xfail_if_format_is_uncomparable(extension):
151+
def _skip_if_format_is_uncomparable(extension):
152152
import pytest
153-
return pytest.mark.xfail(
153+
return pytest.mark.skipif(
154154
extension not in comparable_formats(),
155-
reason='Cannot compare {} files on this system'.format(extension),
156-
raises=ImageComparisonFailure, strict=True)
155+
reason='Cannot compare {} files on this system'.format(extension))
157156

158157

159-
def _mark_xfail_if_format_is_uncomparable(extension):
158+
def _mark_skip_if_format_is_uncomparable(extension):
159+
import pytest
160160
if isinstance(extension, str):
161161
name = extension
162162
marks = []
163163
elif isinstance(extension, tuple):
164164
# Extension might be a pytest ParameterSet instead of a plain string.
165165
# Unfortunately, this type is not exposed, so since it's a namedtuple,
166166
# check for a tuple instead.
167-
name = extension.values[0]
168-
marks = list(extension.marks)
167+
name, = extension.values
168+
marks = [*extension.marks]
169169
else:
170170
# Extension might be a pytest marker instead of a plain string.
171-
name = extension.args[0]
171+
name, = extension.args
172172
marks = [extension.mark]
173-
174-
if name not in comparable_formats():
175-
fail_msg = 'Cannot compare %s files on this system' % (name, )
176-
import pytest
177-
marks += [pytest.mark.xfail(reason=fail_msg, strict=False,
178-
raises=ImageComparisonFailure)]
179-
return pytest.param(name, marks=marks)
180-
else:
181-
return extension
173+
return pytest.param(name,
174+
marks=[*marks, _skip_if_format_is_uncomparable(name)])
182175

183176

184177
class _ImageComparisonBase(object):
@@ -279,7 +272,7 @@ def teardown(self):
279272
def nose_runner(self):
280273
func = self.compare
281274
func = _checked_on_freetype_version(self.freetype_version)(func)
282-
funcs = {extension: _xfail_if_format_is_uncomparable(extension)(func)
275+
funcs = {extension: _skip_if_format_is_uncomparable(extension)(func)
283276
for extension in self.extensions}
284277
for idx, baseline in enumerate(self.baseline_images):
285278
for extension in self.extensions:
@@ -310,7 +303,7 @@ def _pytest_image_comparison(baseline_images, extensions, tol,
310303
"""
311304
import pytest
312305

313-
extensions = map(_mark_xfail_if_format_is_uncomparable, extensions)
306+
extensions = map(_mark_skip_if_format_is_uncomparable, extensions)
314307

315308
def decorator(func):
316309
@functools.wraps(func)
@@ -365,7 +358,7 @@ def image_comparison(baseline_images, extensions=None, tol=0,
365358
calls to :meth:`matplotlib.figure.savefig`.
366359
367360
If *None*, the test function must use the ``baseline_images`` fixture,
368-
either as a parameter or with pytest.mark.usefixtures. This value is
361+
either as a parameter or with `pytest.mark.usefixtures`. This value is
369362
only allowed when using pytest.
370363
371364
extensions : [ None | list ]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.