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
36 changes: 16 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ env:
- NPROC=2
- INSTALL_PEP8=
- RUN_PEP8=
- NOSE_ARGS="-j $NPROC"
- PYTEST_ARGS="-ra --maxfail=1 --timeout=300 --durations=25 --cov-report= --cov=lib -n $NPROC"
- PYTHON_ARGS=
- DELETE_FONT_CACHE=
Expand All @@ -58,7 +57,7 @@ matrix:
- python: 3.4
env: PYTHON_ARGS=-OO
- python: 3.5
env: PANDAS=pandas NOSE_ARGS=--with-coverage DELETE_FONT_CACHE=1
env: PANDAS=pandas DELETE_FONT_CACHE=1
- python: 3.5
env: BUILD_DOCS=true
- python: 3.5
Expand All @@ -70,7 +69,7 @@ matrix:
- os: osx
osx_image: xcode7.3
language: generic # https://github.com/travis-ci/travis-ci/issues/2312
env: MOCK=mock NOSE_ARGS=
env: MOCK=mock
cache:
# As for now travis caches only "$HOME/.cache/pip"
# https://docs.travis-ci.com/user/caching/#pip-cache
Expand Down Expand Up @@ -117,9 +116,6 @@ install:
pip install $PRE python-dateutil $NUMPY pyparsing!=2.1.6 $PANDAS cycler coveralls coverage $MOCK
pip install $PRE -r doc-requirements.txt

# Install nose from a build which has partial
# support for python36 and suport for coverage output suppressing
pip install git+https://github.com/jenshnielsen/nose.git@matplotlibnose
# pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124
pip install $PRE pytest 'pytest-cov>=2.3.1' pytest-timeout pytest-xdist pytest-faulthandler $INSTALL_PEP8

Expand Down Expand Up @@ -155,21 +151,20 @@ script:
if [[ $DELETE_FONT_CACHE == 1 ]]; then
rm -rf ~/.cache/matplotlib
fi
# Workaround for pytest-xdist flaky collection order
# https://github.com/pytest-dev/pytest/issues/920
# https://github.com/pytest-dev/pytest/issues/1075
export PYTHONHASHSEED=$(shuf -i 1-4294967295 -n 1)
echo PYTHONHASHSEED=$PYTHONHASHSEED

echo The following args are passed to pytest $PYTEST_ARGS $RUN_PEP8
if [[ $USE_PYTEST == false ]]; then
echo The following args are passed to nose $NOSE_ARGS $RUN_PEP8
if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
python tests.py $NOSE_ARGS $RUN_PEP8
python tests.py $PYTEST_ARGS $RUN_PEP8
else
gdb -return-child-result -batch -ex r -ex bt --args python $PYTHON_ARGS tests.py $NOSE_ARGS $RUN_PEP8
gdb -return-child-result -batch -ex r -ex bt --args python $PYTHON_ARGS tests.py $PYTEST_ARGS $RUN_PEP8
fi
else
# Workaround for pytest-xdist flaky colletion order
# https://github.com/pytest-dev/pytest/issues/920
# https://github.com/pytest-dev/pytest/issues/1075
export PYTHONHASHSEED=$(shuf -i 1-4294967295 -n 1)
echo PYTHONHASHSEED=$PYTHONHASHSEED

echo The following args are passed to pytest $PYTEST_ARGS $RUN_PEP8
py.test $PYTEST_ARGS $RUN_PEP8
fi
else
Expand Down Expand Up @@ -201,6 +196,11 @@ after_failure:
fi

after_success:
- |
if [[ $BUILD_DOCS == false ]]; then
coveralls
bash <(curl -s https://codecov.io/bash)
fi
- |
if [[ $TRAVIS_PULL_REQUEST == false && $TRAVIS_REPO_SLUG == 'matplotlib/matplotlib' && $BUILD_DOCS == true && $TRAVIS_BRANCH == 'master' ]]; then
cd $TRAVIS_BUILD_DIR
Expand All @@ -225,7 +225,3 @@ after_success:
else
echo "Will only deploy docs build from matplotlib master branch"
fi
if [[ $NOSE_ARGS =~ "--with-coverage" || $USE_PYTEST == true ]]; then
coveralls
bash <(curl -s https://codecov.io/bash)
fi
18 changes: 9 additions & 9 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ environment:
CMD_IN_ENV: "cmd /E:ON /V:ON /C obvci_appveyor_python_build_env.cmd"
# Workaround for https://github.com/conda/conda-build/issues/636
PYTHONIOENCODING: "UTF-8"
PYTEST_ARGS: -ra --timeout=300 --durations=25 #--cov-report= --cov=lib #-n %NUMBER_OF_PROCESSORS%
PYTEST_ARGS: -ra --timeout=300 --durations=25 -n %NUMBER_OF_PROCESSORS% #--cov-report= --cov=lib
USE_PYTEST: no
#PYTHONHASHSEED: 0 # Workaround for pytest-xdist flaky colletion order
# # https://github.com/pytest-dev/pytest/issues/920
# # https://github.com/pytest-dev/pytest/issues/1075
PYTHONHASHSEED: 0 # Workaround for pytest-xdist flaky collection order
# https://github.com/pytest-dev/pytest/issues/920
# https://github.com/pytest-dev/pytest/issues/1075

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

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

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

Expand Down
76 changes: 0 additions & 76 deletions conftest.py

This file was deleted.

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 = kwargs.pop('argv', [])
if not any(os.path.exists(arg) for arg in args):
args += ['--pyargs'] + default_test_modules

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

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

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
2 changes: 1 addition & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ def gca(self, **kwargs):
else:
warnings.warn('Requested projection is different from '
'current axis projection, creating new axis '
'with requested projection.')
'with requested projection.', stacklevel=2)

# no axes found, so create one which spans the figure
return self.add_subplot(1, 1, 1, **kwargs)
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,13 +1284,16 @@ def findfont(self, prop, fontext='ttf', directory=None,
cached = _lookup_cache[fontext].get(prop)
if cached is not None:
return cached
else:
directory = os.path.normcase(directory)

best_score = 1e64
best_font = None

for font in fontlist:
if (directory is not None and
os.path.commonprefix([font.fname, directory]) != directory):
os.path.commonprefix([os.path.normcase(font.fname),
directory]) != directory):
continue
# Matching family should have highest priority, so it is multiplied
# by 10.0
Expand Down
5 changes: 4 additions & 1 deletion lib/matplotlib/gridspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,6 @@ def get_position(self, fig, return_all=False):
else:
return figbox


def get_topmost_subplotspec(self):
'get the topmost SubplotSpec instance associated with the subplot'
gridspec = self.get_gridspec()
Expand All @@ -473,6 +472,10 @@ def __eq__(self, other):
self.num1 == other.num1,
self.num2 == other.num2))

if six.PY2:
def __ne__(self, other):
return not self == other

def __hash__(self):
return (hash(self._gridspec) ^
hash(self.num1) ^
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/sphinxext/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from matplotlib.tests.conftest import mpl_test_settings
from matplotlib.tests.conftest import (mpl_test_settings,
pytest_configure, pytest_unconfigure)
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
import matplotlib


def pytest_configure(config):
matplotlib.use('agg')
matplotlib._called_from_pytest = True
matplotlib._init_tests()


def pytest_unconfigure(config):
matplotlib._called_from_pytest = False


@pytest.fixture(autouse=True)
def mpl_test_settings(request):
from matplotlib.testing.decorators import _do_cleanup
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/tests/test_backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,8 @@ def test_xelatex():
def test_pdflatex():
import os
if os.environ.get('APPVEYOR', False):
from matplotlib.testing import xfail
xfail("pdflatex test does not work on appveyor due "
"to missing latex fonts")
pytest.xfail("pdflatex test does not work on appveyor due to missing "
"LaTeX fonts")

rc_pdflatex = {'font.family': 'serif',
'pgf.rcfonts': False,
Expand Down
Loading