|
10 | 10 | import pytest |
11 | 11 |
|
12 | 12 |
|
13 | | -@pytest.fixture(autouse=True) |
14 | | -def mpl_test_settings(qt_core, mpl_test_settings): |
15 | | - """ |
16 | | - Ensure qt_core fixture is *first* fixture. |
17 | | -
|
18 | | - We override the `mpl_test_settings` fixture and depend on the `qt_core` |
19 | | - fixture first. It is very important that it is first, because it skips |
20 | | - tests when Qt is not available, and if not, then the main |
21 | | - `mpl_test_settings` fixture will try to switch backends before the skip can |
22 | | - be triggered. |
23 | | - """ |
24 | | - |
25 | | - |
26 | 13 | @pytest.fixture |
27 | 14 | def qt_core(request): |
28 | 15 | backend, = request.node.get_closest_marker('backend').args |
29 | | - if backend == 'Qt4Agg': |
30 | | - if any(k in sys.modules for k in ('PyQt5', 'PySide2')): |
31 | | - pytest.skip('Qt5 binding already imported') |
32 | | - try: |
33 | | - import PyQt4 |
34 | | - # RuntimeError if PyQt5 already imported. |
35 | | - except (ImportError, RuntimeError): |
36 | | - try: |
37 | | - import PySide |
38 | | - except ImportError: |
39 | | - pytest.skip("Failed to import a Qt4 binding.") |
40 | | - elif backend == 'Qt5Agg': |
41 | | - if any(k in sys.modules for k in ('PyQt4', 'PySide')): |
42 | | - pytest.skip('Qt4 binding already imported') |
43 | | - try: |
44 | | - import PyQt5 |
45 | | - # RuntimeError if PyQt4 already imported. |
46 | | - except (ImportError, RuntimeError): |
47 | | - try: |
48 | | - import PySide2 |
49 | | - except ImportError: |
50 | | - pytest.skip("Failed to import a Qt5 binding.") |
51 | | - else: |
52 | | - raise ValueError('Backend marker has unknown value: ' + backend) |
53 | | - |
54 | 16 | qt_compat = pytest.importorskip('matplotlib.backends.qt_compat') |
55 | 17 | QtCore = qt_compat.QtCore |
56 | 18 |
|
|
0 commit comments