lundi 1 février 2016

Hide critical messages when testing PyQt

I have a GUI, which works well, under any circumstances. No error, no critical messages.
I want to test some elements, so I wrote the code:

import unittest import logging import sys from PyQt4.QtTest import QTest from PyQt4 import QtGui, QtCore from gui import MainWindow

class TestMainWindow(unittest.TestCase):

    def setUp(self):
        self.app = QtGui.QApplication([])
        # this is for disabling messages from logger
        logging.disable(logging.CRITICAL)

    def test_only_first_checked(self):
        self.ui = MainWindow()
        self.assertEqual(self.ui.first_radio.isChecked(), True)
        self.assertEqual(self.ui.second_radio.isChecked(), False)
        self.assertEqual(self.ui.third_radio.isChecked(), False)

    def test_bottom_radios_disabled(self):
        self.ui = MainWindow()
        self.assertEqual(self.ui.left_radio.isEnabled(), False)
        self.assertEqual(self.ui.right_radio.isEnabled(), False)

And the output is - a lot of lines like:

(python3:12405): Gtk-CRITICAL **: IA__gtk_container_add: assertion 'GTK_IS_CONTAINER (container)' failed

(python3:12405): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion 'GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed

(python3:12405): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion 'GTK_WIDGET_ANCHORED (widget) || GTK_IS_INVISIBLE (widget)' failed

and then

----------------------------------------------------------------------
Ran 2 tests in 0.546s
OK

I've never gotten any of this error messages when running GUI, so I'm wondering If it's possible to disable/hide them.

Aucun commentaire:

Enregistrer un commentaire