Skip to content

Switch testing to pytest completely #7974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use pytest in matplotlib.test().
  • Loading branch information
QuLogic committed Feb 2, 2017
commit 80281e9cab63887c2d944fbf497887360eb7bd0c
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 @@
#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just remove this script?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not against it, but also not going to make that decision unilaterally.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly prefer this script stay and remain functional.

# $ 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)