From 47dca02c1b1b2eb98b74cf54b77fed6a71cd39c6 Mon Sep 17 00:00:00 2001
From: Eric Firing <efiring@hawaii.edu>
Date: Sat, 25 May 2019 09:26:12 -1000
Subject: [PATCH] Backport PR #14139: TST: be more explicit about identifying
 qt4/qt5 imports

---
 lib/matplotlib/tests/test_backend_qt.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/matplotlib/tests/test_backend_qt.py b/lib/matplotlib/tests/test_backend_qt.py
index 625623367f03..f6493cfb9c38 100644
--- a/lib/matplotlib/tests/test_backend_qt.py
+++ b/lib/matplotlib/tests/test_backend_qt.py
@@ -1,4 +1,5 @@
 import copy
+import sys
 from unittest import mock
 
 import matplotlib
@@ -26,6 +27,8 @@ def mpl_test_settings(qt_module, mpl_test_settings):
 def qt_module(request):
     backend, = request.node.get_closest_marker('backend').args
     if backend == 'Qt4Agg':
+        if any(k in sys.modules for k in ('PyQt5', 'PySide2')):
+            pytest.skip('Qt5 binding already imported')
         try:
             import PyQt4
         # RuntimeError if PyQt5 already imported.
@@ -35,6 +38,8 @@ def qt_module(request):
             except ImportError:
                 pytest.skip("Failed to import a Qt4 binding.")
     elif backend == 'Qt5Agg':
+        if any(k in sys.modules for k in ('PyQt4', 'PySide')):
+            pytest.skip('Qt4 binding already imported')
         try:
             import PyQt5
         # RuntimeError if PyQt4 already imported.