私はQt
初心者です。私はQt
に基づいてユーザーインターフェイスライブラリを開発しています。メインQApplication
をsetUp
に開始し、それをtearDown
で終了したいので、テストの間に漏れたイベントやその他の問題はありません。ここでは今、私のsetUp
/tearDown
方法です:`unittest`フレームワークで` QApplication`を停止して再起動するには?
class _QtTest(unittest.TestCase):
def setUp(self):
"""Set up a QAppplication on each test case."""
try:
QApplication = QtGui.QApplication
except AttributeError:
QApplication = QtWidgets.QApplication
self.qt_app = QApplication.instance()
if self.qt_app is None:
self.qt_app = QApplication(sys.argv)
def tearDown(self):
"""Clear the QApplication's event queue."""
# After each test, empty the event queue.
# This should help to make sure that there aren't any event-based race
# conditions where a C/C++ object is deleted before a slot is called.
self.qt_app.sendPostedEvents()
self.qt_app.quit()
は、残念ながらその最後self.qt_app.quit()
は、すべての連続したテストに恒久的にQApplication
をシャットダウンするようです。 setUp
メソッドで新しいQApplication
を再起動する方法はありますか?
あなたは[pytest](https://docs.pytest.org/en/latest/)と[pytest-qt](https://pypi.python.org/pypi/pytest- qt)plugin?私はこれらのどちらも使いませんでしたが、どちらも成熟した、よく整備されたプロジェクトであり、合理的に良い[documentation](https://pytest-qt.readthedocs.io/en/latest/)となっています。 – ekhumoro