@@ -424,9 +424,9 @@ def test_qt_missing():
424424
425425
426426def _impl_test_cross_Qt_imports ():
427- import sys
428427 import importlib
429- import pytest
428+ import sys
429+ import warnings
430430
431431 _ , host_binding , mpl_binding = sys .argv
432432 # import the mpl binding. This will force us to use that binding
@@ -436,11 +436,12 @@ def _impl_test_cross_Qt_imports():
436436 host_qwidgets = importlib .import_module (f'{ host_binding } .QtWidgets' )
437437
438438 host_app = host_qwidgets .QApplication (["mpl testing" ])
439- with pytest .warns (UserWarning , match = "Mixing Qt major" ):
440- matplotlib .backends .backend_qt ._create_qApp ()
439+ warnings .filterwarnings ("error" , message = r".*Mixing Qt major.*" ,
440+ category = UserWarning )
441+ matplotlib .backends .backend_qt ._create_qApp ()
441442
442443
443- def test_cross_Qt_imports ():
444+ def qt5_and_qt6_pairs ():
444445 qt5_bindings = [
445446 dep for dep in ['PyQt5' , 'PySide2' ]
446447 if importlib .util .find_spec (dep ) is not None
@@ -450,25 +451,29 @@ def test_cross_Qt_imports():
450451 if importlib .util .find_spec (dep ) is not None
451452 ]
452453 if len (qt5_bindings ) == 0 or len (qt6_bindings ) == 0 :
453- pytest .skip ('need both QT6 and QT5 bindings' )
454+ yield pytest .param (None , None ,
455+ marks = [pytest .mark .skip ('need both QT6 and QT5 bindings' )])
456+ return
454457
455458 for qt5 in qt5_bindings :
456459 for qt6 in qt6_bindings :
457460 for pair in ([qt5 , qt6 ], [qt6 , qt5 ]):
458- try :
459- _run_helper (_impl_test_cross_Qt_imports ,
460- * pair ,
461- timeout = _test_timeout )
462- except subprocess .CalledProcessError as ex :
463- # if segfault, carry on. We do try to warn the user they
464- # are doing something that we do not expect to work
465- if ex .returncode == - signal .SIGSEGV :
466- continue
467- # We got the abort signal which is likely because the Qt5 /
468- # Qt6 cross import is unhappy, carry on.
469- elif ex .returncode == - signal .SIGABRT :
470- continue
471- raise
461+ yield pair
462+
463+
464+ @pytest .mark .parametrize ('host, mpl' , [* qt5_and_qt6_pairs ()])
465+ def test_cross_Qt_imports (host , mpl ):
466+ try :
467+ proc = _run_helper (_impl_test_cross_Qt_imports , host , mpl ,
468+ timeout = _test_timeout )
469+ except subprocess .CalledProcessError as ex :
470+ # We do try to warn the user they are doing something that we do not
471+ # expect to work, so we're going to ignore if the subprocess crashes or
472+ # is killed, and just check that the warning is printed.
473+ stderr = ex .stderr
474+ else :
475+ stderr = proc .stderr
476+ assert "Mixing Qt major versions may not work as expected." in stderr
472477
473478
474479@pytest .mark .skipif ('TF_BUILD' in os .environ ,
0 commit comments