8000 Merge pull request #13918 from anntzer/noseless · matplotlib/matplotlib@ca63953 · GitHub
[go: up one dir, main page]

Skip to content

Commit ca63953

Browse files
authored
Merge pull request #13918 from anntzer/noseless
Make matplotlib.testing assume pytest by default, not nose.
2 parents 3f9389e + bba95a0 commit ca63953

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Deprecations
2+
````````````
3+
4+
Support in `matplotlib.testing` for nose-based tests is deprecated (a
5+
deprecation is emitted if using e.g. the decorators from that module while
6+
both 1) matplotlib's conftests have not been called and 2) nose is in
7+
``sys.modules``).
8+
9+
``testing.is_called_from_pytest`` is deprecated.
10+
11+
During the deprecation period, to force the generation of nose base tests,
12+
import nose first.
13+
14+
API changes
15+
```````````
16+
17+
The default value of the "obj_type" parameter to ``cbook.warn_deprecated`` has
18+
been changed from "attribute" (a default that was never used internally) to the
19+
empty string.

lib/matplotlib/cbook/deprecation.py

Lines changed: 3 additions & 3 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class MatplotlibDeprecationWarning(UserWarning):
2222

2323

2424
def _generate_deprecation_warning(
25-
since, message='', name='', alternative='', pending=False,
26-
obj_type='attribute', addendum='', *, removal=''):
25+
since, message='', name='', alternative='', pending=False, obj_type='',
26+
addendum='', *, removal=''):
2727
if pending:
2828
if removal:
2929
raise ValueError(
@@ -55,7 +55,7 @@ def _generate_deprecation_warning(
5555

5656
def warn_deprecated(
5757
since, *, message='', name='', alternative='', pending=False,
58-
obj_type='attribute', addendum='', removal=''):
58+
obj_type='', addendum='', removal=''):
5959
"""
6060
Used to display deprecation in a standard way.
6161

lib/matplotlib/testing/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import locale
55
import logging
6+
import sys
67
import warnings
78

89
import matplotlib as mpl
@@ -11,11 +12,20 @@
1112
_log = logging.getLogger(__name__)
1213

1314

15+
@cbook.deprecated("3.2")
1416
def is_called_from_pytest():
1517
"""Whether we are in a pytest run."""
1618
return getattr(mpl, '_called_from_pytest', False)
1719

1820

21+
def _wants_nose():
22+
wants_nose = (not getattr(mpl, '_called_from_pytest', False)
23+
and 'nose' in sys.modules)
24+
if wants_nose:
25+
cbook.warn_deprecated("3.2", name="support for nose-based tests")
26+
return wants_nose
27+
28+
1929
def set_font_settings_for_testing():
2030
mpl.rcParams['font.family'] = 'DejaVu Sans'
2131
mpl.rcParams['text.hinting'] = False

lib/matplotlib/testing/compare.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,13 +311,12 @@ def convert(filename, cache):
311311
base, extension = filename.rsplit('.', 1)
312312
if extension not in converter:
313313
reason = "Don't know how to convert %s files to png" % extension
314-
from . import is_called_from_pytest
315-
if is_called_from_pytest():
316-
import pytest
317-
pytest.skip(reason)
318-
else:
314+
if mpl.testing._wants_nose():
319315
from nose import SkipTest
320316
raise SkipTest(reason)
317+
else:
318+
import pytest
319+
pytest.skip(reason)
321320
newname = base + '_' + extension + '.png'
322321
if not os.path.exists(filename):
323322
raise IOError("'%s' does not exist" % filename)

lib/matplotlib/testing/decorators.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,19 +403,19 @@ def image_comparison(baseline_images, extensions=None, tol=0,
403403
#default no kwargs to savefig
404404
savefig_kwarg = dict()
405405

406-
if is_called_from_pytest():
407-
return _pytest_image_comparison(
408-
baseline_images=baseline_images, extensions=extensions, tol=tol,
409-
freetype_version=freetype_version, remove_text=remove_text,
410-
savefig_kwargs=savefig_kwarg, style=style)
411-
else:
406+
if mpl.testing._wants_nose():
412407
if baseline_images is None:
413408
raise ValueError('baseline_images must be specified')
414409

415410
return ImageComparisonTest(
416411
baseline_images=baseline_images, extensions=extensions, tol=tol,
417412
freetype_version=freetype_version, remove_text=remove_text,
418413
savefig_kwargs=savefig_kwarg, style=style)
414+
else:
415+
return _pytest_image_comparison(
416+
baseline_images=baseline_images, extensions=extensions, tol=tol,
417+
freetype_version=freetype_version, remove_text=remove_text,
418+
savefig_kwargs=savefig_kwarg, style=style)
419419

420420

421421
def check_figures_equal(*, extensions=("png", "pdf", "svg"), tol=0):

0 commit comments

Comments
 (0)
0