简体   繁体   English

在测试PyQt时隐藏关键消息

[英]Hide critical messages when testing PyQt

I have a GUI, which works well, under any circumstances. 我有一个GUI,在任何情况下都可以正常工作。 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 导入unittest导入日志记录从PyQt4.QtTest导入sys从PyQt4导入QTest从gui导入QtGui,QtCore导入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_container_add:断言'GTK_IS_CONTAINER(container)'失败

(python3:12405): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion 'GTK_WIDGET_ANCHORED (widget) || (python3:12405):Gtk关键**:IA__gtk_widget_realize:断言'GTK_WIDGET_ANCHORED(widget)|| GTK_IS_INVISIBLE (widget)' failed GTK_IS_INVISIBLE(widget)'失败

(python3:12405): Gtk-CRITICAL **: IA__gtk_widget_realize: assertion 'GTK_WIDGET_ANCHORED (widget) || (python3:12405):Gtk关键**:IA__gtk_widget_realize:断言'GTK_WIDGET_ANCHORED(widget)|| GTK_IS_INVISIBLE (widget)' failed GTK_IS_INVISIBLE(widget)'失败

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. 在运行GUI时,我从未收到任何此类错误消息,因此我想知道是否可以禁用/隐藏它们。

Added to TestMainWindow 添加到TestMainWindow

def tearDown(self):
    self.app.deleteLater()

and now it doesn't show any critical message. 现在它没有显示任何重要消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM