Skip to content

Only print actually tested QT APIs when erroring #25772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ def _isdeleted(obj):
else:
raise ImportError(
"Failed to import any of the following Qt binding modules: {}"
.format(", ".join(_ETS.values())))
.format(", ".join([QT_API for _, QT_API in _candidates]))
)
else: # We should not get there.
raise AssertionError(f"Unexpected QT_API: {QT_API}")
_version_info = tuple(QtCore.QLibraryInfo.version().segments())
Expand Down
20 changes: 20 additions & 0 deletions lib/matplotlib/tests/test_backends_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,26 @@ def test_qt5backends_uses_qt5():
_run_helper(_implcore, timeout=_test_timeout)


def _impl_missing():
import sys
# Simulate uninstalled
sys.modules["PyQt6"] = None
sys.modules["PyQt5"] = None
sys.modules["PySide2"] = None
sys.modules["PySide6"] = None

import matplotlib.pyplot as plt
with pytest.raises(ImportError, match="Failed to import any of the following Qt"):
plt.switch_backend("qtagg")
# Specifically ensure that Pyside6/Pyqt6 are not in the error message for qt5agg
with pytest.raises(ImportError, match="^(?:(?!(PySide6|PyQt6)).)*$"):
plt.switch_backend("qt5agg")


def test_qt_missing():
_run_helper(_impl_missing, timeout=_test_timeout)


def _impl_test_cross_Qt_imports():
import sys
import importlib
Expand Down