Skip to content
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

Update tests to use pytest better #1775

Merged
merged 7 commits into from Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions appveyor.yml
Expand Up @@ -10,9 +10,8 @@ environment:

matrix:
- PYTHON_VERSION: "3.7"
CONDA_DEPENDENCIES: "numpy scipy setuptools pytest coverage pytest-cov pytest-sugar cython coveralls"
PIP_DEPENDENCIES: "numpydoc https://files.pythonhosted.org/packages/71/5f/07aad120ca6e4339a5c127631341787bc6bc74add39a1f41223bda949721/freetype_py-2.1.0.post1-py2.py3-none-win_amd64.whl"
# can remove the github numpydoc install once >0.8.0 is released
CONDA_DEPENDENCIES: "numpy scipy setuptools pytest coverage pytest-cov pytest-sugar pytest-faulthandler cython coveralls freetype-py numpydoc"
PIP_DEPENDENCIES: ""

platform:
-x64
Expand Down
2 changes: 2 additions & 0 deletions azure-pipelines.yml
Expand Up @@ -51,6 +51,8 @@ jobs:
- {task: UsePythonVersion@0, inputs: {versionSpec: '3.6', architecture: x64}}
- {task: UsePythonVersion@0, inputs: {versionSpec: '3.7', architecture: x86}}
- {task: UsePythonVersion@0, inputs: {versionSpec: '3.7', architecture: x64}}
- {task: UsePythonVersion@0, inputs: {versionSpec: '3.8', architecture: x86}}
- {task: UsePythonVersion@0, inputs: {versionSpec: '3.8', architecture: x64}}
- bash: |
git submodule update --init --recursive
python -m pip install --upgrade pip
Expand Down
35 changes: 13 additions & 22 deletions vispy/testing/_testing.py
Expand Up @@ -11,13 +11,16 @@
import os
import inspect
import gc
import pytest
import functools

from distutils.version import LooseVersion

from ..ext.six import string_types
from ..util import use_log_level

skipif = pytest.mark.skipif


def SkipTest(*args, **kwargs):
"""Backport for raising SkipTest that gives a better traceback."""
Expand All @@ -26,10 +29,6 @@ def SkipTest(*args, **kwargs):
return pytest.skip(*args, **kwargs)


###############################################################################
# Adapted from Python's unittest2
# http://docs.python.org/2/license.html

def _safe_rep(obj, short=False):
"""Helper for assert_* ports"""
try:
Expand Down Expand Up @@ -150,21 +149,20 @@ def __exit__(self, exc_typ, exc, tb):
def has_pyopengl():
try:
from OpenGL import GL # noqa, analysis:ignore
except Exception:
except ImportError:
return False
else:
return True


def requires_pyopengl():
import pytest
return pytest.mark.skipif(not has_pyopengl(), reason='Requires PyOpenGL')
skip = not has_pyopengl()
return skipif(skip, reason='Requires PyOpenGL')


def requires_ssl():
import pytest
bad = os.getenv('CIBW_BUILDING', 'false') == 'true'
return pytest.mark.skipif(bad, reason='Requires proper SSL support')
return skipif(bad, reason='Requires proper SSL support')


###############################################################################
Expand Down Expand Up @@ -242,9 +240,8 @@ def deco(*args, **kwargs):

def requires_application(backend=None, has=(), capable=(), force_gc=True):
"""Return a decorator for tests that require an application"""
import pytest
good, msg = has_application(backend, has, capable)
dec_backend = pytest.mark.skipif(not good, reason="Skipping test: %s" % msg)
dec_backend = skipif(not good, reason="Skipping test: %s" % msg)
try:
import pytest
except Exception:
Expand All @@ -258,14 +255,12 @@ def requires_application(backend=None, has=(), capable=(), force_gc=True):

def requires_img_lib():
"""Decorator for tests that require an image library"""
import pytest
from ..io import _check_img_lib
if sys.platform.startswith('win'):
has_img_lib = False # PIL breaks tests on windows (!)
else:
has_img_lib = not all(c is None for c in _check_img_lib())
return pytest.mark.skipif(
not has_img_lib, reason='imageio or PIL required')
return skipif(not has_img_lib, reason='imageio or PIL required')


def has_ipython(version='3.0'):
Expand All @@ -291,20 +286,18 @@ def has_ipython(version='3.0'):


def requires_ipython(version='3.0'):
import pytest
ipython_present, message = has_ipython(version)
return pytest.mark.skipif(not ipython_present, reason=message)
return skipif(not ipython_present, reason=message)


def requires_numpydoc():
import pytest
try:
import numpydoc # noqa
except Exception:
present = False
else:
present = True
return pytest.mark.skipif(not present, reason='numpydoc is required')
return skipif(not present, reason='numpydoc is required')


def has_matplotlib(version='1.2'):
Expand Down Expand Up @@ -349,10 +342,8 @@ def _has_scipy(min_version):


def requires_scipy(min_version='0.13'):
import pytest
return pytest.mark.skipif(
not _has_scipy(min_version),
reason='Requires Scipy version >= %s' % min_version)
return skipif(not _has_scipy(min_version),
reason='Requires Scipy version >= %s' % min_version)


def _bad_glfw_decorate(app):
Expand Down