Skip to content

TST: Remove qt_core fixture #30398

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 1 commit into from
Aug 7, 2025
Merged
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
26 changes: 10 additions & 16 deletions lib/matplotlib/tests/test_backend_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from matplotlib import _c_internal_utils

try:
from matplotlib.backends.qt_compat import QtCore # type: ignore[attr-defined]
from matplotlib.backends.qt_compat import QtGui # type: ignore[attr-defined] # noqa: E501, F401
from matplotlib.backends.qt_compat import QtWidgets # type: ignore[attr-defined]
from matplotlib.backends.qt_editor import _formlayout
Expand All @@ -25,12 +26,6 @@
_test_timeout = 60 # A reasonably safe value for slower architectures.


@pytest.fixture
def qt_core(request):
from matplotlib.backends.qt_compat import QtCore
return QtCore


@pytest.mark.backend('QtAgg', skip_on_importerror=True)
def test_fig_close():

Expand Down Expand Up @@ -101,7 +96,7 @@ def test_fig_close():
'QtAgg',
marks=pytest.mark.backend('QtAgg', skip_on_importerror=True)),
])
def test_correct_key(backend, qt_core, qt_key, qt_mods, answer, monkeypatch):
def test_correct_key(backend, qt_key, qt_mods, answer, monkeypatch):
"""
Make a figure.
Send a key_press_event event (using non-public, qtX backend specific api).
Expand Down Expand Up @@ -137,7 +132,7 @@ def on_key_press(event):


@pytest.mark.backend('QtAgg', skip_on_importerror=True)
def test_device_pixel_ratio_change(qt_core):
def test_device_pixel_ratio_change():
"""
Make sure that if the pixel ratio changes, the figure dpi changes but the
widget remains the same logical size.
Expand All @@ -155,12 +150,11 @@ def set_device_pixel_ratio(ratio):
p.return_value = ratio

window = qt_canvas.window().windowHandle()
current_version = tuple(
int(x) for x in qt_core.qVersion().split('.', 2)[:2])
current_version = tuple(int(x) for x in QtCore.qVersion().split('.', 2)[:2])
if current_version >= (6, 6):
qt_core.QCoreApplication.sendEvent(
QtCore.QCoreApplication.sendEvent(
window,
qt_core.QEvent(qt_core.QEvent.Type.DevicePixelRatioChange))
QtCore.QEvent(QtCore.QEvent.Type.DevicePixelRatioChange))
else:
# The value here doesn't matter, as we can't mock the C++ QScreen
# object, but can override the functional wrapper around it.
Expand Down Expand Up @@ -342,7 +336,7 @@ def _get_testable_qt_backends():


@pytest.mark.backend('QtAgg', skip_on_importerror=True)
def test_fig_sigint_override(qt_core):
def test_fig_sigint_override():
from matplotlib.backends.backend_qt5 import _BackendQT5
# Create a figure
plt.figure()
Expand All @@ -357,10 +351,10 @@ def fire_signal_and_quit():
event_loop_handler = signal.getsignal(signal.SIGINT)

# Request event loop exit
qt_core.QCoreApplication.exit()
QtCore.QCoreApplication.exit()

# Timer to exit event loop
qt_core.QTimer.singleShot(0, fire_signal_and_quit)
QtCore.QTimer.singleShot(0, fire_signal_and_quit)

# Save original SIGINT handler
original_handler = signal.getsignal(signal.SIGINT)
Expand All @@ -385,7 +379,7 @@ def custom_handler(signum, frame):

# Repeat again to test that SIG_DFL and SIG_IGN will not be overridden
for custom_handler in (signal.SIG_DFL, signal.SIG_IGN):
qt_core.QTimer.singleShot(0, fire_signal_and_quit)
QtCore.QTimer.singleShot(0, fire_signal_and_quit)
signal.signal(signal.SIGINT, custom_handler)

_BackendQT5.mainloop()
Expand Down
Loading