Skip to content

Commit 67ed3c8

Browse files
committed
Use pytest in matplotlib.test().
1 parent eef58c5 commit 67ed3c8

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

lib/matplotlib/__init__.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,9 +1474,10 @@ def _jupyter_nbextension_paths():
14741474

14751475

14761476
default_test_modules = [
1477-
'matplotlib.tests.test_png',
1478-
'matplotlib.tests.test_units',
1479-
]
1477+
'matplotlib.tests',
1478+
'matplotlib.sphinxext.tests',
1479+
'mpl_toolkits.tests',
1480+
]
14801481

14811482

14821483
def _init_tests():
@@ -1510,19 +1511,51 @@ def _init_tests():
15101511
)
15111512
)
15121513

1513-
from .testing._nose import check_deps
1514-
check_deps()
1514+
try:
1515+
import pytest
1516+
try:
1517+
from unittest import mock
1518+
except ImportError:
1519+
import mock
1520+
except ImportError:
1521+
print("matplotlib.test requires pytest and mock to run.")
1522+
raise
15151523

15161524

1517-
def test(verbosity=1, coverage=False, **kwargs):
1525+
def test(verbosity=None, coverage=False, switch_backend_warn=True,
1526+
recursionlimit=0, **kwargs):
15181527
"""run the matplotlib test suite"""
15191528
_init_tests()
15201529

1521-
from .testing._nose import test as nose_test
1522-
return nose_test(verbosity, coverage, **kwargs)
1530+
old_backend = get_backend()
1531+
old_recursionlimit = sys.getrecursionlimit()
1532+
try:
1533+
use('agg')
1534+
if recursionlimit:
1535+
sys.setrecursionlimit(recursionlimit)
1536+
import pytest
1537+
1538+
args = ['--pyargs'] + default_test_modules
1539+
1540+
if coverage:
1541+
args += ['--cov']
1542+
1543+
if verbosity:
1544+
args += ['-' + 'v' * verbosity]
1545+
1546+
args += kwargs.pop('argv', [])
1547+
1548+
retcode = pytest.main(args, **kwargs)
1549+
finally:
1550+
if old_backend.lower() != 'agg':
1551+
use(old_backend, warn=switch_backend_warn)
1552+
if recursionlimit:
1553+
sys.setrecursionlimit(old_recursionlimit)
1554+
1555+
return retcode
15231556

15241557

1525-
test.__test__ = False # nose: this function is not a test
1558+
test.__test__ = False # pytest: this function is not a test
15261559

15271560

15281561
def _replacer(data, key):

tests.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
#
55
# $ python tests.py -v -d
66
#
7-
# The arguments are identical to the arguments accepted by nosetests.
7+
# The arguments are identical to the arguments accepted by py.test.
88
#
9-
# See https://nose.readthedocs.org/ for a detailed description of
10-
# these options.
9+
# See http://doc.pytest.org/ for a detailed description of these options.
1110

1211
import sys
1312
import argparse
@@ -17,10 +16,6 @@
1716
from matplotlib import test
1817

1918
parser = argparse.ArgumentParser(add_help=False)
20-
parser.add_argument('--no-pep8', action='store_true',
21-
help='Run all tests except PEP8 testing')
22-
parser.add_argument('--pep8', action='store_true',
23-
help='Run only PEP8 testing')
2419
parser.add_argument('--no-network', action='store_true',
2520
help='Run tests without network connection')
2621
parser.add_argument('-j', type=int,
@@ -32,15 +27,14 @@
3227
if args.no_network:
3328
from matplotlib.testing import disable_internet
3429
disable_internet.turn_off_internet()
35-
extra_args.extend(['-a', '!network'])
30+
extra_args.extend(['-m', 'not network'])
3631
if args.j:
3732
extra_args.extend([
38-
'--processes={}'.format(args.j),
39-
'--process-timeout=300'
33+
'-n', str(args.j),
4034
])
4135

4236
print('Python byte-compilation optimization level: %d' % sys.flags.optimize)
4337

44-
success = test(argv=sys.argv[0:1] + extra_args, switch_backend_warn=False,
38+
retcode = test(argv=extra_args, switch_backend_warn=False,
4539
recursionlimit=args.recursionlimit)
46-
sys.exit(not success)
40+
sys.exit(retcode)

0 commit comments

Comments
 (0)