Skip to content

Commit 04a0de8

Browse files
committed
Don't fail Qt tests if bindings not installed.
1 parent 2f47c6a commit 04a0de8

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

lib/matplotlib/tests/test_backend_qt4.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,18 @@
77

88
import pytest
99

10-
with matplotlib.rc_context(rc={'backend': 'Qt4Agg'}):
11-
qt_compat = pytest.importorskip('matplotlib.backends.qt_compat')
10+
try:
11+
import PyQt4
12+
except (ImportError, RuntimeError): # RuntimeError if PyQt5 already imported.
13+
try:
14+
import PySide
15+
except ImportError:
16+
pytestmark = pytest.mark.skip("Failed to import a Qt4 binding.")
17+
18+
from matplotlib.backends.qt_compat import QtCore
1219
from matplotlib.backends.backend_qt4 import (
1320
MODIFIER_KEYS, SUPER, ALT, CTRL, SHIFT) # noqa
1421

15-
QtCore = qt_compat.QtCore
1622
_, ControlModifier, ControlKey = MODIFIER_KEYS[CTRL]
1723
_, AltModifier, AltKey = MODIFIER_KEYS[ALT]
1824
_, SuperModifier, SuperKey = MODIFIER_KEYS[SUPER]

lib/matplotlib/tests/test_backend_qt5.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@
77

88
import pytest
99

10-
with matplotlib.rc_context(rc={'backend': 'Qt5Agg'}):
11-
qt_compat = pytest.importorskip('matplotlib.backends.qt_compat',
12-
minversion='5')
10+
try:
11+
import PyQt5
12+
except (ImportError, RuntimeError): # RuntimeError if PyQt4 already imported.
13+
try:
14+
import PySide2
15+
except ImportError:
16+
pytestmark = pytest.mark.skip("Failed to import a Qt5 binding.")
17+
18+
from matplotlib.backends.qt_compat import QtCore
1319
from matplotlib.backends.backend_qt5 import (
1420
MODIFIER_KEYS, SUPER, ALT, CTRL, SHIFT) # noqa
1521

16-
QtCore = qt_compat.QtCore
1722
_, ControlModifier, ControlKey = MODIFIER_KEYS[CTRL]
1823
_, AltModifier, AltKey = MODIFIER_KEYS[ALT]
1924
_, SuperModifier, SuperKey = MODIFIER_KEYS[SUPER]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy