Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5bc91c7

Browse files
committed
Move conftest.py so it works with uninstalled tests.
1 parent 4529002 commit 5bc91c7

File tree

4 files changed

+61
-56
lines changed

4 files changed

+61
-56
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33

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

lib/matplotlib/testing/conftest.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
import pytest
5+
6+
import matplotlib
7+
8+
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+
19+
@pytest.fixture(autouse=True)
20+
def mpl_test_settings(request):
21+
from matplotlib.testing.decorators import _do_cleanup
22+
23+
original_units_registry = matplotlib.units.registry.copy()
24+
original_settings = matplotlib.rcParams.copy()
25+
26+
backend = None
27+
backend_marker = request.keywords.get('backend')
28+
if backend_marker is not None:
29+
assert len(backend_marker.args) == 1, \
30+
"Marker 'backend' must specify 1 backend."
31+
backend = backend_marker.args[0]
32+
prev_backend = matplotlib.get_backend()
33+
34+
style = 'classic'
35+
style_marker = request.keywords.get('style')
36+
if style_marker is not None:
37+
assert len(style_marker.args) == 1, \
38+
"Marker 'style' must specify 1 style."
39+
style = style_marker.args[0]
40+
41+
matplotlib.testing.setup()
42+
if backend is not None:
43+
# This import must come after setup() so it doesn't load the default
44+
# backend prematurely.
45+
import matplotlib.pyplot as plt
46+
plt.switch_backend(backend)
47+
matplotlib.style.use(style)
48+
try:
49+
yield
50+
finally:
51+
if backend is not None:
52+
import matplotlib.pyplot as plt
53+
plt.switch_backend(prev_backend)
54+
_do_cleanup(original_units_registry,
55+
original_settings)

lib/matplotlib/tests/conftest.py

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,5 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33

4-
import pytest
5-
6-
import matplotlib
7-
8-
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-
19-
@pytest.fixture(autouse=True)
20-
def mpl_test_settings(request):
21-
from matplotlib.testing.decorators import _do_cleanup
22-
23-
original_units_registry = matplotlib.units.registry.copy()
24-
original_settings = matplotlib.rcParams.copy()
25-
26-
backend = None
27-
backend_marker = request.keywords.get('backend')
28-
if backend_marker is not None:
29-
assert len(backend_marker.args) == 1, \
30-
"Marker 'backend' must specify 1 backend."
31-
backend = backend_marker.args[0]
32-
prev_backend = matplotlib.get_backend()
33-
34-
style = 'classic'
35-
style_marker = request.keywords.get('style')
36-
if style_marker is not None:
37-
assert len(style_marker.args) == 1, \
38-
"Marker 'style' must specify 1 style."
39-
style = style_marker.args[0]
40-
41-
matplotlib.testing.setup()
42-
if backend is not None:
43-
# This import must come after setup() so it doesn't load the default
44-
# backend prematurely.
45-
import matplotlib.pyplot as plt
46-
plt.switch_backend(backend)
47-
matplotlib.style.use(style)
48-
try:
49-
yield
50-
finally:
51-
if backend is not None:
52-
import matplotlib.pyplot as plt
53-
plt.switch_backend(prev_backend)
54-
_do_cleanup(original_units_registry,
55-
original_settings)
4+
from matplotlib.testing.conftest import (mpl_test_settings,
5+
pytest_configure, pytest_unconfigure)

lib/mpl_toolkits/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
33

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

0 commit comments

Comments
 (0)