8000 Merge pull request #16261 from tacaswell/tst_fix_qt_fixtures · matplotlib/matplotlib@cd580da · GitHub
[go: up one dir, main page]

Skip to content

Commit cd580da

Browse files
authored
Merge pull request #16261 from tacaswell/tst_fix_qt_fixtures
TST: move the Qt-specific handling to conftest
2 parents efbc555 + 44a92d5 commit cd580da

File tree

3 files changed

+26
-40
lines changed

3 files changed

+26
-40
lines changed

lib/matplotlib/testing/conftest.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
2+
import sys
33
import matplotlib
44
from matplotlib import cbook
55

@@ -45,6 +45,30 @@ def mpl_test_settings(request):
4545
'skip_on_importerror', False)
4646
prev_backend = matplotlib.get_backend()
4747

48+
# special case Qt backend importing to avoid conflicts
49+
if backend.lower().startswith('qt4'):
50+
if any(k in sys.modules for k in ('PyQt5', 'PySide2')):
51+
pytest.skip('Qt5 binding already imported')
52+
try:
53+
import PyQt4
54+
# RuntimeError if PyQt5 already imported.
55+
except (ImportError, RuntimeError):
56+
try:
57+
import PySide
58+
except ImportError:
59+
pytest.skip("Failed to import a Qt4 binding.")
60+
elif backend.lower().startswith('qt5'):
61+
if any(k in sys.modules for k in ('PyQt4', 'PySide')):
62+
pytest.skip('Qt4 binding already imported')
63+
try:
64+
import PyQt5
65+
# RuntimeError if PyQt4 already imported.
66+
except (ImportError, RuntimeError):
67+
try:
68+
import PySide2
69+
except ImportError:
70+
pytest.skip("Failed to import a Qt5 binding.")
71+
4872
# Default of cleanup and image_comparison too.
4973
style = ["classic", "_classic_test_patch"]
5074
style_marker = request.node.get_closest_marker('style')

lib/matplotlib/tests/test_backend_qt.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,9 @@
1010
import pytest
1111

1212

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-
2613
@pytest.fixture
2714
def qt_core(request):
2815
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-
5416
qt_compat = pytest.importorskip('matplotlib.backends.qt_compat')
5517
QtCore = qt_compat.QtCore
5618

requirements/testing/travis_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cycler
55
numpy
66
pillow
77
pyparsing
8-
pytest!=4.6.0,!=5.3.3
8+
pytest!=4.6.0
99
pytest-cov
1010
pytest-rerunfailures
1111
pytest-timeout

0 commit comments

Comments
 (0)
0