You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created some end to end test that work correctly in my local machine (Win11 22H). These tests use a fixture that manage the instances of QApplication and the main QMainWidget. The goal is to load the aplication and perform some setup actions. This fixture returns the instance of QApplication. In each test the QMainWidget instance is accesed using QApplication.activeWindow() method.
When tests are executed by GitHub action the QApplication.activeWindow() returns None. I tried returning the QMainWidget instance but it looks like there is an error in its creation.
=================================== FAILURES ===================================
| ____________________________________ test_1 ____________________________________
|
| qtbot = <pytestqt.qtbot.QtBot object at 0x7f5f6fe22d40>
| app = <PyQt6.QtWidgets.QApplication object at 0x7f5f6fe15e10>
|
| > ???
| E AttributeError: 'NoneType' object has no attribute 'button'
I reproduced the issue creating an script that follows the application structure
import pytest
from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtWidgets import QApplication, QDialogButtonBox
from pyqt.__main__ import Window
@pytest.fixture(scope="function")
def app(qtbot):
test_app: QApplication = QApplication.instance()
if test_app is None:
test_app = QApplication([])
window: Window = test_app.activeWindow()
if window is not None:
window.close()
# Application reset
window = Window()
window.show()
with qtbot.waitExposed(window):
yield test_app
test_app.quit()
def test_1(qtbot, app):
window: Window = app.activeWindow()
dialog_handled = False
def handle_dialog():
dialog = window.current_dialog
while not dialog:
dialog = window.current_dialog
dialog.button_box.button(QDialogButtonBox.StandardButton.Ok).click()
nonlocal dialog_handled
dialog_handled = True
QTimer.singleShot(5, handle_dialog)
qtbot.mouseClick(window.button, Qt.MouseButton.LeftButton)
assert dialog_handled
For testing purposes I am using act in order to test locally the actions. To completly reproduce the failure using act some extra dependencies must be installed (xvfb libnss3 libxdamage1 libasound2). Workflow:
I managed to partially solve the error including the fixture code inside the test. It only worked for one of the tests in the original repository (test_open_project). The other tests, as well as the example reproduction, completly freeze the console (both local and remote) when this "workaround" is applied. test_open_project test is the only one that does not deal with a custom QDialog but a QFileDialog with mocked features.
I am new to the qt world so I am bit confused with the life cycle management of the widgets and dialog management when testing. The workaround for dialog testing was taken from #237 .
Here it is the list of python libraries used in the project:
I managed to fix this changing the fixture aproach and using headless-gui to run the tests as pointed in #510.
The fixture now just return Window instance, also use addWidget to properly handle the life cycle of the widget. Active dialog is accesed using activeModalWidget().
I created some end to end test that work correctly in my local machine (Win11 22H). These tests use a fixture that manage the instances of
QApplication
and the mainQMainWidget
. The goal is to load the aplication and perform some setup actions. This fixture returns the instance ofQApplication
. In each test theQMainWidget
instance is accesed usingQApplication.activeWindow()
method.When tests are executed by GitHub action the
QApplication.activeWindow()
returns None. I tried returning theQMainWidget
instance but it looks like there is an error in its creation.I reproduced the issue creating an script that follows the application structure
Simple app with dialog:
Test:
For testing purposes I am using act in order to test locally the actions. To completly reproduce the failure using act some extra dependencies must be installed (xvfb libnss3 libxdamage1 libasound2). Workflow:
Here is the original workflow error from GitHub in the original repository.
I managed to partially solve the error including the fixture code inside the test. It only worked for one of the tests in the original repository (test_open_project). The other tests, as well as the example reproduction, completly freeze the console (both local and remote) when this "workaround" is applied.
test_open_project
test is the only one that does not deal with a custom QDialog but a QFileDialog with mocked features.I am new to the qt world so I am bit confused with the life cycle management of the widgets and dialog management when testing. The workaround for dialog testing was taken from #237 .
Here it is the list of python libraries used in the project:
The text was updated successfully, but these errors were encountered: