8000 Use pytest in matplotlib.test(). · matplotlib/matplotlib@80281e9 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

8000
Appearance settings

Commit 80281e9

Browse files
committed
Use pytest in matplotlib.test().
1 parent 30e40c6 commit 80281e9

File tree

3 files changed

+49
-28
lines changed

3 files changed

+49
-28
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ env:
4545
- NPROC=2
4646
- INSTALL_PEP8=
4747
- RUN_PEP8=
48-
- NOSE_ARGS="-j $NPROC"
48+
- NOSE_ARGS="-n $NPROC"
4949
- PYTEST_ARGS="-ra --maxfail=1 --timeout=300 --durations=25 --cov-report= --cov=lib -n $NPROC"
5050
- PYTHON_ARGS=
5151
- DELETE_FONT_CACHE=

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 & 18 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
@@ -39,30 +38,19 @@
3938
from matplotlib import test
4039

4140
parser = argparse.ArgumentParser(add_help=False)
42-
parser.add_argument('--no-pep8', action='store_true',
43-
help='Run all tests except PEP8 testing')
44-
parser.add_argument('--pep8', action='store_true',
45-
help='Run only PEP8 testing')
4641
parser.add_argument('--no-network', action='store_true',
4742
help='Run tests without network connection')
48-
parser.add_argument('-j', type=int,
49-
help='Shortcut for specifying number of test processes')
5043
parser.add_argument('--recursionlimit', type=int, default=0,
5144
help='Specify recursionlimit for test run')
5245
args, extra_args = parser.parse_known_args()
5346

5447
if args.no_network:
5548
from matplotlib.testing import disable_internet
5649
disable_internet.turn_off_internet()
57-
extra_args.extend(['-a', '!network'])
58-
if args.j:
59-
extra_args.extend([
60-
'--processes={}'.format(args.j),
61-
'--process-timeout=300'
62-
])
50+
extra_args.extend(['-m', 'not network'])
6351

64-
print('Python byte-compilation optimization level: %d' % sys.flags.optimize)
52+
print('Python byte-compilation optimization level:', sys.flags.optimize)
6553

66-
success = test(argv=sys.argv[0:1] + extra_args, switch_backend_warn=False,
54+
retcode = test(argv=extra_args, switch_backend_warn=False,
6755
recursionlimit=args.recursionlimit)
68-
sys.exit(not success)
56+
sys.exit(retcode)

0 commit comments

Comments
 (0)
0