I am trying to test my PyQt app. I need to view results of my unittest in PyQt widget but when I run unittesting the app closes.
This is my code: validation_test_app.py:
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkRequest
import sys
import unittest
def get_size(url):
manager = QNetworkAccessManager()
response = manager.get(QNetworkRequest(QtCore.QUrl(r"https://" + url)))
event = QtCore.QEventLoop()
response.finished.connect(event.quit)
event.exec()
html = response.readAll()
size = html.size()
return size
class MainWindow(QtWidgets.QWidget):
def __init__(self, parent = None):
super(MainWindow, self).__init__()
self.layout = QtWidgets.QVBoxLayout()
self.label = QtWidgets.QLabel("Checking tests...")
self.btn = QtWidgets.QPushButton("push")
self.btn.clicked.connect(self.btn_clicked)
self.layout.addWidget(self.label, alignment=QtCore.Qt.AlignCenter)
self.layout.addWidget(self.btn)
self.setLayout(self.layout)
def btn_clicked(self):
unittest.main(module="validation_test")
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
main_window = MainWindow()
main_window.show()
sys.exit(app.exec_())
validation_test.py:
import unittest
from validation_test_app import get_size
class TestUrls(unittest.TestCase):
def test_1(self):
size = get_size("apps4all.ru")
self.assertEqual(size, 0)
def test_2(self):
size = get_size("google.com")
self.assertNotEqual(size, 0)
I want to view results of testing in QLabel, for example. Is it real to implement ?
Aucun commentaire:
Enregistrer un commentaire