|
1 | 1 | from __future__ import (absolute_import, division, print_function, |
2 | 2 | unicode_literals) |
3 | 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) |
| 4 | +from matplotlib.testing.conftest import (mpl_test_settings, |
| 5 | + pytest_configure, pytest_unconfigure) |
0 commit comments