Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4a3780b

Browse filesBrowse files
committed
TST: Check cross Qt import results from parent process
We are only interested in whether we emitted the warning, and don't care if the test segfaults or otherwise crashes. Thus it is better to check the output from the parent process, instead of `pytest.warns` in the subprocess and checking the return code.
1 parent 65d7e08 commit 4a3780b
Copy full SHA for 4a3780b

File tree

Expand file treeCollapse file tree

1 file changed

+25
-20
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+25
-20
lines changed

‎lib/matplotlib/tests/test_backends_interactive.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backends_interactive.py
+25-20Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,9 @@ def test_qt_missing():
424424

425425

426426
def _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

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.