From 49e2b0e948e03762424c699dc6f69dff99e222a6 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 27 Mar 2018 18:26:18 -0700 Subject: [PATCH] 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. --- lib/matplotlib/testing/decorators.py | 43 ++++++---------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/lib/matplotlib/testing/decorators.py b/lib/matplotlib/testing/decorators.py index d579a4713535..3ae35920c31b 100644 --- a/lib/matplotlib/testing/decorators.py +++ b/lib/matplotlib/testing/decorators.py @@ -27,27 +27,6 @@ from .exceptions import ImageComparisonFailure -def _knownfailureif(fail_condition, msg=None, known_exception_class=None): - """ - - Assume a will fail if *fail_condition* is True. *fail_condition* - may also be False or the string 'indeterminate'. - - *msg* is the error message displayed for the test. - - If *known_exception_class* is not None, the failure is only known - if the exception is an instance of this class. (Default = None) - - """ - import pytest - if fail_condition == 'indeterminate': - fail_condition, strict = True, False - else: - fail_condition, strict = bool(fail_condition), True - return pytest.mark.xfail(condition=fail_condition, reason=msg, - raises=known_exception_class, strict=strict) - - def _do_cleanup(original_units_registry, original_settings): plt.close('all') @@ -152,14 +131,13 @@ def check_freetype_version(ver): def _checked_on_freetype_version(required_freetype_version): - if check_freetype_version(required_freetype_version): - return lambda f: f - + import pytest reason = ("Mismatched version of freetype. " "Test requires '%s', you have '%s'" % (required_freetype_version, ft2font.__freetype_version__)) - return _knownfailureif('indeterminate', msg=reason, - known_exception_class=ImageComparisonFailure) + return pytest.mark.xfail( + not check_freetype_version(required_freetype_version), + reason=reason, raises=ImageComparisonFailure, strict=False) def remove_ticks_and_titles(figure): @@ -195,14 +173,11 @@ def _raise_on_image_difference(expected, actual, tol): def _xfail_if_format_is_uncomparable(extension): - will_fail = extension not in comparable_formats() - if will_fail: - fail_msg = 'Cannot compare %s files on this system' % extension - else: - fail_msg = 'No failure expected' - - return _knownfailureif(will_fail, fail_msg, - known_exception_class=ImageComparisonFailure) + import pytest + return pytest.mark.xfail( + extension not in comparable_formats(), + reason='Cannot compare {} files on this system'.format(extension), + raises=ImageComparisonFailure, strict=True) def _mark_xfail_if_format_is_uncomparable(extension):