From feed240869cbe95559f932efb37590d419e9fe25 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 2 Jul 2021 16:14:00 +0530 Subject: [PATCH] DEV : Catch deprecation warning thrown by QtScript import pyface.qt.QtScript is expected to throw a deprecation warning on PyQt5/PySide2, which the new test checks, while also swallowing the deprecation warning and making the test output cleaner. modified: pyface/ui/qt4/tests/test_qt_imports.py --- pyface/ui/qt4/tests/test_qt_imports.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/pyface/ui/qt4/tests/test_qt_imports.py b/pyface/ui/qt4/tests/test_qt_imports.py index b4059e691..311343d92 100644 --- a/pyface/ui/qt4/tests/test_qt_imports.py +++ b/pyface/ui/qt4/tests/test_qt_imports.py @@ -9,6 +9,7 @@ # Thanks for using Enthought open source! import unittest +import warnings class TestPyfaceQtImports(unittest.TestCase): @@ -18,9 +19,21 @@ def test_imports(self): import pyface.qt.QtGui import pyface.qt.QtNetwork import pyface.qt.QtOpenGL - import pyface.qt.QtScript import pyface.qt.QtSvg import pyface.qt.QtTest import pyface.qt.QtWebKit import pyface.qt.QtMultimedia import pyface.qt.QtMultimediaWidgets + + def test_import_QtScript(self): + # QtScript is not supported on PyQt5/PySide2 and + # this import will raise a deprecation warning. + with warnings.catch_warnings(record=True) as w: + # Cause all warnings to always be triggered. + warnings.simplefilter("always", category=DeprecationWarning) + + import pyface.qt.QtScript + + self.assertTrue(len(w) == 1) + for warn in w: + self.assertEqual(warn.category, DeprecationWarning)