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

Skip to content

Commit 49e2b0e

Browse files
committed
Inline knownfailureif.
Now that nose support has been dropped, knownfailureif is just a thin wrapper around pytest.mark.xfail that's more obfuscating the purpose of the code than anything else.
1 parent 0d0eb39 commit 49e2b0e

File tree

1 file changed

+9
-34
lines changed

1 file changed

+9
-34
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,6 @@
2727
from .exceptions import ImageComparisonFailure
2828

2929

30-
def _knownfailureif(fail_condition, msg=None, known_exception_class=None):
31-
"""
32-
33-
Assume a will fail if *fail_condition* is True. *fail_condition*
34-
may also be False or the string 'indeterminate'.
35-
36-
*msg* is the error message displayed for the test.
37-
38-
If *known_exception_class* is not None, the failure is only known
39-
if the exception is an instance of this class. (Default = None)
40-
41-
"""
42-
import pytest
43-
if fail_condition == 'indeterminate':
44-
fail_condition, strict = True, False
45-
else:
46-
fail_condition, strict = bool(fail_condition), True
47-
return pytest.mark.xfail(condition=fail_condition, reason=msg,
48-
raises=known_exception_class, strict=strict)
49-
50-
5130
def _do_cleanup(original_units_registry, original_settings):
5231
plt.close('all')
5332

@@ -152,14 +131,13 @@ def check_freetype_version(ver):
152131

153132

154133
def _checked_on_freetype_version(required_freetype_version):
155-
if check_freetype_version(required_freetype_version):
156-
return lambda f: f
157-
134+
import pytest
158135
reason = ("Mismatched version of freetype. "
159136
"Test requires '%s', you have '%s'" %
160137
(required_freetype_version, ft2font.__freetype_version__))
161-
return _knownfailureif('indeterminate', msg=reason,
162-
known_exception_class=ImageComparisonFailure)
138+
return pytest.mark.xfail(
139+
not check_freetype_version(required_freetype_version),
140+
reason=reason, raises=ImageComparisonFailure, strict=False)
163141

164142

165143
def remove_ticks_and_titles(figure):
@@ -195,14 +173,11 @@ def _raise_on_image_difference(expected, actual, tol):
195173

196174

197175
def _xfail_if_format_is_uncomparable(extension):
198-
will_fail = extension not in comparable_formats()
199-
if will_fail:
200-
fail_msg = 'Cannot compare %s files on this system' % extension
201-
else:
202-
fail_msg = 'No failure expected'
203-
204-
return _knownfailureif(will_fail, fail_msg,
205-
known_exception_class=ImageComparisonFailure)
176+
import pytest
177+
return pytest.mark.xfail(
178+
extension not in comparable_formats(),
179+
reason='Cannot compare {} files on this system'.format(extension),
180+
raises=ImageComparisonFailure, strict=True)
206181

207182

208183
def _mark_xfail_if_format_is_uncomparable(extension):

0 commit comments

Comments
 (0)