Skip to content

Commit

Permalink
Use pytest in matplotlib.test().
Browse files Browse the repository at this point in the history
  • Loading branch information
QuLogic committed Feb 2, 2017
1 parent 30e40c6 commit 80281e9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ env:
- NPROC=2
- INSTALL_PEP8=
- RUN_PEP8=
- NOSE_ARGS="-j $NPROC"
- NOSE_ARGS="-n $NPROC"
- PYTEST_ARGS="-ra --maxfail=1 --timeout=300 --durations=25 --cov-report= --cov=lib -n $NPROC"
- PYTHON_ARGS=
- DELETE_FONT_CACHE=
Expand Down
51 changes: 42 additions & 9 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,9 +1474,10 @@ def _jupyter_nbextension_paths():


default_test_modules = [
'matplotlib.tests.test_png',
'matplotlib.tests.test_units',
]
'matplotlib.tests',
'matplotlib.sphinxext.tests',
'mpl_toolkits.tests',
]


def _init_tests():
Expand Down Expand Up @@ -1510,19 +1511,51 @@ def _init_tests():
)
)

from .testing._nose import check_deps
check_deps()
try:
import pytest
try:
from unittest import mock
except ImportError:
import mock
except ImportError:
print("matplotlib.test requires pytest and mock to run.")
raise


def test(verbosity=1, coverage=False, **kwargs):
def test(verbosity=None, coverage=False, switch_backend_warn=True,
recursionlimit=0, **kwargs):
"""run the matplotlib test suite"""
_init_tests()

from .testing._nose import test as nose_test
return nose_test(verbosity, coverage, **kwargs)
old_backend = get_backend()
old_recursionlimit = sys.getrecursionlimit()
try:
use('agg')
if recursionlimit:
sys.setrecursionlimit(recursionlimit)
import pytest

args = ['--pyargs'] + default_test_modules

if coverage:
args += ['--cov']

if verbosity:
args += ['-' + 'v' * verbosity]

args += kwargs.pop('argv', [])

retcode = pytest.main(args, **kwargs)
finally:
if old_backend.lower() != 'agg':
use(old_backend, warn=switch_backend_warn)
if recursionlimit:
sys.setrecursionlimit(old_recursionlimit)

return retcode


test.__test__ = False # nose: this function is not a test
test.__test__ = False # pytest: this function is not a test


def _replacer(data, key):
Expand Down
24 changes: 6 additions & 18 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#
# $ python tests.py -v -d
#
# The arguments are identical to the arguments accepted by nosetests.
# The arguments are identical to the arguments accepted by py.test.
#
# See https://nose.readthedocs.org/ for a detailed description of
# these options.
# See http://doc.pytest.org/ for a detailed description of these options.

import sys
import argparse
Expand Down Expand Up @@ -39,30 +38,19 @@
from matplotlib import test

parser = argparse.ArgumentParser(add_help=False)
parser.add_argument('--no-pep8', action='store_true',
help='Run all tests except PEP8 testing')
parser.add_argument('--pep8', action='store_true',
help='Run only PEP8 testing')
parser.add_argument('--no-network', action='store_true',
help='Run tests without network connection')
parser.add_argument('-j', type=int,
help='Shortcut for specifying number of test processes')
parser.add_argument('--recursionlimit', type=int, default=0,
help='Specify recursionlimit for test run')
args, extra_args = parser.parse_known_args()

if args.no_network:
from matplotlib.testing import disable_internet
disable_internet.turn_off_internet()
extra_args.extend(['-a', '!network'])
if args.j:
extra_args.extend([
'--processes={}'.format(args.j),
'--process-timeout=300'
])
extra_args.extend(['-m', 'not network'])

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

success = test(argv=sys.argv[0:1] + extra_args, switch_backend_warn=False,
retcode = test(argv=extra_args, switch_backend_warn=False,
recursionlimit=args.recursionlimit)
sys.exit(not success)
sys.exit(retcode)

0 comments on commit 80281e9

Please sign in to comment.