tests: Destroy Qt objects left behind by GUI tests - #1548
Open
apyrgio wants to merge 1 commit into
Open
Conversation
By the time a GUI test is over, pytest-qt has called `close()` and `deleteLater()` on every widget registered with `qtbot.addWidget()`, and has run `processEvents()` a few times. That is not enough to actually destroy them: * `deleteLater()` merely posts a DeferredDelete event, and Qt delivers those only from within a running event loop. There is none at teardown time, so the deletions pile up unprocessed. * The widgets that the application creates without a parent, such as `MainWindow.file_dialog` or the various `Alert` dialogs, are not registered with pytest-qt in the first place. The result is that a Qt test leaves roughly a dozen live widgets behind, and since pytest holds on to the fixtures that reference them for the whole session, they are only ever destroyed by the interpreter's final garbage collection pass -- in an order that PySide does not control, and possibly after the QApplication itself is gone. On Windows this occasionally faults *after* pytest has already reported the test as passed, which fails the CI run with no indication of which test process died. So we destroy them here instead, while the QApplication is still alive and we are still in control of the ordering. Refs #493 Closes #1547
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By the time a GUI test is over, pytest-qt has called
close()anddeleteLater()on every widget registered withqtbot.addWidget(), and has runprocessEvents()a few times. That is not enough to actually destroy them:deleteLater()merely posts a DeferredDelete event, and Qt delivers those only from within a running event loop. There is none at teardown time, so the deletions pile up unprocessed.MainWindow.file_dialogor the variousAlertdialogs, are not registered with pytest-qt in the first place.The result is that a Qt test leaves roughly a dozen live widgets behind, and since pytest holds on to the fixtures that reference them for the whole session, they are only ever destroyed by the interpreter's final garbage collection pass -- in an order that PySide does not control, and possibly after the QApplication itself is gone. On Windows this occasionally faults after pytest has already reported the test as passed, which fails the CI run with no indication of which test process died.
So we destroy them here instead, while the QApplication is still alive and we are still in control of the ordering.
Refs #493
Closes #1547