Skip to content

Commit a517c60

Browse files
authored
Merge pull request #7974 from QuLogic/pytest
Switch testing to pytest completely
2 parents 1f999f4 + fe20a23 commit a517c60

15 files changed

+113
-144
lines changed

.travis.yml

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ env:
4545
- NPROC=2
4646
- INSTALL_PEP8=
4747
- RUN_PEP8=
48-
- NOSE_ARGS="-j $NPROC"
4948
- PYTEST_ARGS="-ra --maxfail=1 --timeout=300 --durations=25 --cov-report= --cov=lib -n $NPROC"
5049
- PYTHON_ARGS=
5150
- DELETE_FONT_CACHE=
@@ -58,7 +57,7 @@ matrix:
5857
- python: 3.4
5958
env: PYTHON_ARGS=-OO
6059
- python: 3.5
61-
env: PANDAS=pandas NOSE_ARGS=--with-coverage DELETE_FONT_CACHE=1
60+
env: PANDAS=pandas DELETE_FONT_CACHE=1
6261
- python: 3.5
6362
env: BUILD_DOCS=true
6463
- python: 3.5
@@ -70,7 +69,7 @@ matrix:
7069
- os: osx
7170
osx_image: xcode7.3
7271
language: generic # https://github.com/travis-ci/travis-ci/issues/2312
73-
env: MOCK=mock NOSE_ARGS=
72+
env: MOCK=mock
7473
cache:
7574
# As for now travis caches only "$HOME/.cache/pip"
7675
# https://docs.travis-ci.com/user/caching/#pip-cache
@@ -117,9 +116,6 @@ install:
117116
pip install $PRE python-dateutil $NUMPY pyparsing!=2.1.6 $PANDAS cycler coveralls coverage $MOCK
118117
pip install $PRE -r doc-requirements.txt
119118
120-
# Install nose from a build which has partial
121-
# support for python36 and suport for coverage output suppressing
122-
pip install git+https://github.com/jenshnielsen/nose.git@matplotlibnose
123119
# pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124
124120
pip install $PRE pytest 'pytest-cov>=2.3.1' pytest-timeout pytest-xdist pytest-faulthandler $INSTALL_PEP8
125121
@@ -155,21 +151,20 @@ script:
155151
if [[ $DELETE_FONT_CACHE == 1 ]]; then
156152
rm -rf ~/.cache/matplotlib
157153
fi
154+
# Workaround for pytest-xdist flaky collection order
155+
# https://github.com/pytest-dev/pytest/issues/920
156+
# https://github.com/pytest-dev/pytest/issues/1075
157+
export PYTHONHASHSEED=$(shuf -i 1-4294967295 -n 1)
158+
echo PYTHONHASHSEED=$PYTHONHASHSEED
159+
160+
echo The following args are passed to pytest $PYTEST_ARGS $RUN_PEP8
158161
if [[ $USE_PYTEST == false ]]; then
159-
echo The following args are passed to nose $NOSE_ARGS $RUN_PEP8
160162
if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
161-
python tests.py $NOSE_ARGS $RUN_PEP8
163+
python tests.py $PYTEST_ARGS $RUN_PEP8
162164
else
163-
gdb -return-child-result -batch -ex r -ex bt --args python $PYTHON_ARGS tests.py $NOSE_ARGS $RUN_PEP8
165+
gdb -return-child-result -batch -ex r -ex bt --args python $PYTHON_ARGS tests.py $PYTEST_ARGS $RUN_PEP8
164166
fi
165167
else
166-
# Workaround for pytest-xdist flaky colletion order
167-
# https://github.com/pytest-dev/pytest/issues/920
168-
# https://github.com/pytest-dev/pytest/issues/1075
169-
export PYTHONHASHSEED=$(shuf -i 1-4294967295 -n 1)
170-
echo PYTHONHASHSEED=$PYTHONHASHSEED
171-
172-
echo The following args are passed to pytest $PYTEST_ARGS $RUN_PEP8
173168
py.test $PYTEST_ARGS $RUN_PEP8
174169
fi
175170
else
@@ -201,6 +196,11 @@ after_failure:
201196
fi
202197
203198
after_success:
199+
- |
200+
if [[ $BUILD_DOCS == false ]]; then
201+
coveralls
202+
bash <(curl -s https://codecov.io/bash)
203+
fi
204204
- |
205205
if [[ $TRAVIS_PULL_REQUEST == false && $TRAVIS_REPO_SLUG == 'matplotlib/matplotlib' && $BUILD_DOCS == true && $TRAVIS_BRANCH == 'master' ]]; then
206206
cd $TRAVIS_BUILD_DIR
@@ -225,7 +225,3 @@ after_success:
225225
else
226226
echo "Will only deploy docs build from matplotlib master branch"
227227
fi
228-
if [[ $NOSE_ARGS =~ "--with-coverage" || $USE_PYTEST == true ]]; then
229-
coveralls
230-
bash <(curl -s https://codecov.io/bash)
231-
fi

appveyor.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ environment:
1414
CMD_IN_ENV: "cmd /E:ON /V:ON /C obvci_appveyor_python_build_env.cmd"
1515
# Workaround for https://github.com/conda/conda-build/issues/636
1616
PYTHONIOENCODING: "UTF-8"
17-
PYTEST_ARGS: -ra --timeout=300 --durations=25 #--cov-report= --cov=lib #-n %NUMBER_OF_PROCESSORS%
17+
PYTEST_ARGS: -ra --timeout=300 --durations=25 -n %NUMBER_OF_PROCESSORS% #--cov-report= --cov=lib
1818
USE_PYTEST: no
19-
#PYTHONHASHSEED: 0 # Workaround for pytest-xdist flaky colletion order
20-
# # https://github.com/pytest-dev/pytest/issues/920
21-
# # https://github.com/pytest-dev/pytest/issues/1075
19+
PYTHONHASHSEED: 0 # Workaround for pytest-xdist flaky collection order
20+
# https://github.com/pytest-dev/pytest/issues/920
21+
# https://github.com/pytest-dev/pytest/issues/1075
2222

2323
matrix:
2424
# for testing purpose: numpy 1.8 on py2.7, for the rest use 1.10/latest
@@ -91,12 +91,12 @@ install:
9191
- conda create -q -n test-environment python=%PYTHON_VERSION%
9292
pip setuptools numpy python-dateutil freetype=2.6 msinttypes "tk=8.5"
9393
pyparsing pytz tornado "libpng>=1.6.21,<1.7" "zlib=1.2" "cycler>=0.10"
94-
nose mock sphinx
94+
mock sphinx
9595
- activate test-environment
9696
- cmd: echo %PYTHON_VERSION% %TARGET_ARCH%
9797
- cmd: IF %PYTHON_VERSION% == 2.7 conda install -q functools32
9898
# pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124
99-
- if x%USE_PYTEST% == xyes conda install -q pytest "pytest-cov>=2.3.1" pytest-timeout #pytest-xdist
99+
- conda install -q pytest "pytest-cov>=2.3.1" pytest-timeout pytest-xdist
100100

101101
# Let the install prefer the static builds of the libs
102102
- set LIBRARY_LIB=%CONDA_PREFIX%\Library\lib
@@ -116,7 +116,7 @@ install:
116116

117117
test_script:
118118
# Now build the thing..
119-
- '%CMD_IN_ENV% python setup.py develop'
119+
- '%CMD_IN_ENV% pip install --no-deps -ve .'
120120
# these should show no z, png, or freetype dll...
121121
- set "DUMPBIN=%VS140COMNTOOLS%\..\..\VC\bin\dumpbin.exe"
122122
#- cmd: '"%DUMPBIN%" /DEPENDENTS lib\matplotlib\_png*.pyd'
@@ -135,9 +135,9 @@ test_script:
135135
# Test import of tkagg backend
136136
- python -c "import matplotlib as m; m.use('tkagg'); import matplotlib.pyplot as plt; print(plt.get_backend())"
137137
# tests
138-
- if x%USE_PYTEST% == xyes echo The following args are passed to pytest %PYTEST_ARGS%
138+
- echo The following args are passed to pytest %PYTEST_ARGS%
139139
- if x%USE_PYTEST% == xyes py.test %PYTEST_ARGS%
140-
- if x%USE_PYTEST% == xno python tests.py
140+
- if x%USE_PYTEST% == xno python tests.py %PYTEST_ARGS%
141141
# Generate a html for visual tests
142142
- python visual_tests.py
143143

conftest.py

Lines changed: 0 additions & 76 deletions
This file was deleted.

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 = kwargs.pop('argv', [])
1539+
if not any(os.path.exists(arg) for arg in args):
1540+
args += ['--pyargs'] + default_test_modules
1541+
1542+
if coverage:
1543+
args += ['--cov']
1544+
1545+
if verbosity:
1546+
args += ['-' + 'v' * verbosity]
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):

lib/matplotlib/figure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ def gca(self, **kwargs):
15551555
else:
15561556
warnings.warn('Requested projection is different from '
15571557
'current axis projection, creating new axis '
1558-
'with requested projection.')
1558+
'with requested projection.', stacklevel=2)
15591559

15601560
# no axes found, so create one which spans the figure
15611561
return self.add_subplot(1, 1, 1, **kwargs)

lib/matplotlib/font_manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,13 +1284,16 @@ def findfont(self, prop, fontext='ttf', directory=None,
12841284
cached = _lookup_cache[fontext].get(prop)
12851285
if cached is not None:
12861286
return cached
1287+
else:
1288+
directory = os.path.normcase(directory)
12871289

12881290
best_score = 1e64
12891291
best_font = None
12901292

12911293
for font in fontlist:
12921294
if (directory is not None and
1293-
os.path.commonprefix([font.fname, directory]) != directory):
1295+
os.path.commonprefix([os.path.normcase(font.fname),
1296+
directory]) != directory):
12941297
continue
12951298
# Matching family should have highest priority, so it is multiplied
12961299
# by 10.0

lib/matplotlib/gridspec.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,6 @@ def get_position(self, fig, return_all=False):
453453
else:
454454
return figbox
455455

456-
457456
def get_topmost_subplotspec(self):
458457
'get the topmost SubplotSpec instance associated with the subplot'
459458
gridspec = self.get_gridspec()
@@ -473,6 +472,10 @@ def __eq__(self, other):
473472
self.num1 == other.num1,
474473
self.num2 == other.num2))
475474

475+
if six.PY2:
476+
def __ne__(self, other):
477+
return not self == other
478+
476479
def __hash__(self):
477480
return (hash(self._gridspec) ^
478481
hash(self.num1) ^
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33

4-
from matplotlib.tests.conftest import mpl_test_settings
4+
from matplotlib.tests.conftest import (mpl_test_settings,
5+
pytest_configure, pytest_unconfigure)

lib/matplotlib/tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
import matplotlib
77

88

9+
def pytest_configure(config):
10+
matplotlib.use('agg')
11+
matplotlib._called_from_pytest = True
12+
matplotlib._init_tests()
13+
14+
15+
def pytest_unconfigure(config):
16+
matplotlib._called_from_pytest = False
17+
18+
919
@pytest.fixture(autouse=True)
1020
def mpl_test_settings(request):
1121
from matplotlib.testing.decorators import _do_cleanup

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,8 @@ def test_xelatex():
9999
def test_pdflatex():
100100
import os
101101
if os.environ.get('APPVEYOR', False):
102-
from matplotlib.testing import xfail
103-
xfail("pdflatex test does not work on appveyor due "
104-
"to missing latex fonts")
102+
pytest.xfail("pdflatex test does not work on appveyor due to missing "
103+
"LaTeX fonts")
105104

106105
rc_pdflatex = {'font.family': 'serif',
107106
'pgf.rcfonts': False,

0 commit comments

Comments
 (0)