Skip to content

Pytest documentation + build tweaks #8026

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 20, 2017
Merged
Prev Previous commit
Next Next commit
Move conftest.py so it works with uninstalled tests.
  • Loading branch information
QuLogic committed Feb 16, 2017
commit 5bc91c7c394e29e9f4b87b1d24c4a331ef30ea28
4 changes: 2 additions & 2 deletions lib/matplotlib/sphinxext/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from matplotlib.tests.conftest import (mpl_test_settings,
pytest_configure, pytest_unconfigure)
from matplotlib.testing.conftest import (mpl_test_settings,
pytest_configure, pytest_unconfigure)
55 changes: 55 additions & 0 deletions lib/matplotlib/testing/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import pytest

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

original_units_registry = matplotlib.units.registry.copy()
original_settings = matplotlib.rcParams.copy()

backend = None
backend_marker = request.keywords.get('backend')
if backend_marker is not None:
assert len(backend_marker.args) == 1, \
"Marker 'backend' must specify 1 backend."
backend = backend_marker.args[0]
prev_backend = matplotlib.get_backend()

style = 'classic'
style_marker = request.keywords.get('style')
if style_marker is not None:
assert len(style_marker.args) == 1, \
"Marker 'style' must specify 1 style."
style = style_marker.args[0]

matplotlib.testing.setup()
if backend is not None:
# This import must come after setup() so it doesn't load the default
# backend prematurely.
import matplotlib.pyplot as plt
plt.switch_backend(backend)
matplotlib.style.use(style)
try:
yield
finally:
if backend is not None:
import matplotlib.pyplot as plt
plt.switch_backend(prev_backend)
_do_cleanup(original_units_registry,
original_settings)
54 changes: 2 additions & 52 deletions lib/matplotlib/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,5 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import pytest

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

original_units_registry = matplotlib.units.registry.copy()
original_settings = matplotlib.rcParams.copy()

backend = None
backend_marker = request.keywords.get('backend')
if backend_marker is not None:
assert len(backend_marker.args) == 1, \
"Marker 'backend' must specify 1 backend."
backend = backend_marker.args[0]
prev_backend = matplotlib.get_backend()

style = 'classic'
style_marker = request.keywords.get('style')
if style_marker is not None:
assert len(style_marker.args) == 1, \
"Marker 'style' must specify 1 style."
style = style_marker.args[0]

matplotlib.testing.setup()
if backend is not None:
# This import must come after setup() so it doesn't load the default
# backend prematurely.
import matplotlib.pyplot as plt
plt.switch_backend(backend)
matplotlib.style.use(style)
try:
yield
finally:
if backend is not None:
import matplotlib.pyplot as plt
plt.switch_backend(prev_backend)
_do_cleanup(original_units_registry,
original_settings)
from matplotlib.testing.conftest import (mpl_test_settings,
pytest_configure, pytest_unconfigure)
4 changes: 2 additions & 2 deletions lib/mpl_toolkits/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

from matplotlib.tests.conftest import (mpl_test_settings,
pytest_configure, pytest_unconfigure)
from matplotlib.testing.conftest import (mpl_test_settings,
pytest_configure, pytest_unconfigure)