@@ -267,7 +267,9 @@ def _implqt5agg():
267267 assert 'PyQt5' in sys .modules or 'pyside2' in sys .modules
268268
269269 import matplotlib .backends .backend_qt5
270- matplotlib .backends .backend_qt5 .qApp
270+ with pytest .warns (DeprecationWarning ,
271+ match = "QtWidgets.QApplication.instance" ):
272+ matplotlib .backends .backend_qt5 .qApp
271273
272274
273275def _implcairo ():
@@ -279,7 +281,9 @@ def _implcairo():
279281 assert 'PyQt5' in sys .modules or 'pyside2' in sys .modules
280282
281283 import matplotlib .backends .backend_qt5
282- matplotlib .backends .backend_qt5 .qApp
284+ with pytest .warns (DeprecationWarning ,
285+ match = "QtWidgets.QApplication.instance" ):
286+ matplotlib .backends .backend_qt5 .qApp
283287
284288
285289def _implcore ():
@@ -289,7 +293,10 @@ def _implcore():
289293 assert 'PyQt6' not in sys .modules
290294 assert 'pyside6' not in sys .modules
291295 assert 'PyQt5' in sys .modules or 'pyside2' in sys .modules
292- matplotlib .backends .backend_qt5 .qApp
296+
297+ with pytest .warns (DeprecationWarning ,
298+ match = "QtWidgets.QApplication.instance" ):
299+ matplotlib .backends .backend_qt5 .qApp
293300
294301
295302def test_qt5backends_uses_qt5 ():
@@ -410,11 +417,25 @@ def _lazy_headless():
410417
411418
412419@pytest .mark .skipif (sys .platform != "linux" , reason = "this a linux-only test" )
413- @pytest .mark .backend ('QtAgg ' , skip_on_importerror = True )
420+ @pytest .mark .backend ('Qt5Agg ' , skip_on_importerror = True )
414421def test_lazy_linux_headless ():
415422 proc = _run_helper (_lazy_headless , timeout = _test_timeout , MPLBACKEND = "" )
416423
417424
425+ def _qApp_warn_impl ():
426+ import matplotlib .backends .backend_qt
427+ import pytest
428+
429+ with pytest .warns (
430+ DeprecationWarning , match = "QtWidgets.QApplication.instance" ):
431+ matplotlib .backends .backend_qt .qApp
432+
433+
434+ @pytest .mark .backend ('QtAgg' , skip_on_importerror = True )
435+ def test_qApp_warn ():
436+ _run_helper (_qApp_warn_impl , timeout = _test_timeout )
437+
438+
418439def _test_number_of_draws_script ():
419440 import matplotlib .pyplot as plt
420441
0 commit comments