Skip to content

Commit 1a6ef99

Browse files
authored
Merge pull request #16990 from terencehonles/update-testing-helpers
TST: update testing helpers
2 parents 42b2dff + 30f7b65 commit 1a6ef99

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

lib/matplotlib/__init__.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1201,29 +1201,29 @@ def _init_tests():
12011201
"Freetype build type is {}local".format(
12021202
"" if ft2font.__freetype_build_type__ == 'local' else "not "))
12031203

1204-
try:
1205-
import pytest
1206-
except ImportError:
1207-
print("matplotlib.test requires pytest to run.")
1208-
raise
1209-
12101204

12111205
@cbook._delete_parameter("3.2", "switch_backend_warn")
12121206
@cbook._delete_parameter("3.3", "recursionlimit")
12131207
def test(verbosity=None, coverage=False, switch_backend_warn=True,
12141208
recursionlimit=0, **kwargs):
12151209
"""Run the matplotlib test suite."""
1216-
_init_tests()
1210+
1211+
try:
1212+
import pytest
1213+
except ImportError:
1214+
print("matplotlib.test requires pytest to run.")
1215+
return -1
1216+
12171217
if not os.path.isdir(os.path.join(os.path.dirname(__file__), 'tests')):
1218-
raise ImportError("Matplotlib test data is not installed")
1218+
print("Matplotlib test data is not installed")
1219+
return -1
12191220

12201221
old_backend = get_backend()
12211222
old_recursionlimit = sys.getrecursionlimit()
12221223
try:
12231224
use('agg')
12241225
if recursionlimit:
12251226
sys.setrecursionlimit(recursionlimit)
1226-
import pytest
12271227

12281228
args = kwargs.pop('argv', [])
12291229
provide_default_modules = True

lib/matplotlib/testing/decorators.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ def _raise_on_image_difference(expected, actual, tol):
134134

135135
err = compare_images(expected, actual, tol, in_decorator=True)
136136
if err:
137-
for key in ["actual", "expected"]:
137+
for key in ["actual", "expected", "diff"]:
138138
err[key] = os.path.relpath(err[key])
139139
raise ImageComparisonFailure(
140-
'images not close (RMS %(rms).3f):\n\t%(actual)s\n\t%(expected)s '
141-
% err)
140+
('images not close (RMS %(rms).3f):'
141+
'\n\t%(actual)s\n\t%(expected)s\n\t%(diff)s') % err)
142142

143143

144144
def _skip_if_format_is_uncomparable(extension):

tests.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313

1414

1515
if __name__ == '__main__':
16-
from matplotlib import test
16+
try:
17+
from matplotlib import test
18+
except ImportError:
19+
print('matplotlib.test could not be imported.\n\n'
20+
'Try a virtual env and `pip install -e .`')
21+
sys.exit(-1)
1722

1823
parser = argparse.ArgumentParser(add_help=False)
1924
parser.add_argument('--recursionlimit', type=int, default=None,

0 commit comments

Comments
 (0)