Skip to content

Commit 9ee77a9

Browse files
committed
Use pytest in matplotlib.test().
1 parent 858df8b commit 9ee77a9

File tree

2 files changed

+42
-22
lines changed

2 files changed

+42
-22
lines changed

lib/matplotlib/__init__.py

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

14751475

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

14821482

14831483
def _init_tests():
@@ -1511,19 +1511,45 @@ def _init_tests():
15111511
)
15121512
)
15131513

1514-
from .testing.nose import check_deps
1515-
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
15161523

15171524

1518-
def test(verbosity=1, coverage=False, **kwargs):
1525+
def test(verbosity=1, coverage=False, switch_backend_warn=True, **kwargs):
15191526
"""run the matplotlib test suite"""
15201527
_init_tests()
15211528

1522-
from .testing.nose import test as nose_test
1523-
return nose_test(verbosity, coverage, **kwargs)
1529+
old_backend = get_backend()
1530+
try:
1531+
use('agg')
1532+
import pytest
1533+
1534+
args = ['--pyargs'] + default_test_modules
1535+
1536+
if coverage:
1537+
args += ['--cov']
1538+
1539+
if verbosity is not None:
1540+
args += ['-' + 'v' * verbosity]
1541+
1542+
args += kwargs.pop('argv', [])
1543+
1544+
retcode = pytest.main(args, **kwargs)
1545+
finally:
1546+
if old_backend.lower() != 'agg':
1547+
use(old_backend, warn=switch_backend_warn)
1548+
1549+
return retcode
15241550

15251551

1526-
test.__test__ = False # nose: this function is not a test
1552+
test.__test__ = False # pytest: this function is not a test
15271553

15281554

15291555
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,
@@ -30,14 +25,13 @@
3025
if args.no_network:
3126
from matplotlib.testing import disable_internet
3227
disable_internet.turn_off_internet()
33-
extra_args.extend(['-a', '!network'])
28+
extra_args.extend(['-m', 'not network'])
3429
if args.j:
3530
extra_args.extend([
36-
'--processes={}'.format(args.j),
37-
'--process-timeout=300'
31+
'-n', str(args.j),
3832
])
3933

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

42-
success = test(argv=sys.argv[0:1] + extra_args, switch_backend_warn=False)
43-
sys.exit(not success)
36+
retcode = test(argv=sys.argv[0:1] + extra_args, switch_backend_warn=False)
37+
sys.exit(retcode)

0 commit comments

Comments
 (0)