Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Delete Qt test windows before the QApplication goes away

v0lumehi0ba9910a0515
diff --git a/frontend-qt/tests/test_build_failure.py b/frontend-qt/tests/test_build_failure.py
index 9369f23f..ccb5fab2 100644
--- a/frontend-qt/tests/test_build_failure.py
+++ b/frontend-qt/tests/test_build_failure.py
@@ -25,6 +25,7 @@ sys.path.insert(0, str(ROOT / 'frontend-qt'))
os.environ.setdefault('QT_QPA_PLATFORM', 'offscreen')
try:
+ from PySide6.QtCore import QEvent
from PySide6.QtWidgets import QApplication, QScrollArea
except ImportError: # the packaged app always has it; a bare python3 may not
QApplication = None
@@ -36,11 +37,20 @@ class BuildFailure(unittest.TestCase):
def setUpClass(cls):
cls.app = QApplication.instance() or QApplication([])
+ def _delete(self, m, w):
+ w.close()
+ w.deleteLater()
+ m.deleteLater()
+ self.app.sendPostedEvents(None, QEvent.DeferredDelete)
+ self.app.processEvents()
+
def _window(self, height: int):
from nspb_qt.model import Model
from nspb_qt.ui import MainWindow
m = Model()
w = MainWindow(m)
+ # Delete while the app exists: PySide destroys leftovers after it at exit and segfaults.
+ self.addCleanup(self._delete, m, w)
w.resize(900, height)
w.show()
for _ in range(3):
diff --git a/frontend-qt/tests/test_build_failure_hints.py b/frontend-qt/tests/test_build_failure_hints.py
index 8524114f..006de102 100644
--- a/frontend-qt/tests/test_build_failure_hints.py
+++ b/frontend-qt/tests/test_build_failure_hints.py
@@ -203,6 +203,7 @@ class Strings(unittest.TestCase):
try:
+ from PySide6.QtCore import QEvent
from PySide6.QtWidgets import QApplication, QMessageBox
except ImportError: # the packaged app always has it; a bare python3 may not
QApplication = None
@@ -219,11 +220,21 @@ class Window(unittest.TestCase):
from nspb_qt.ui import MainWindow
m = Model()
w = MainWindow(m)
+ # A window left alive is destroyed by PySide after the QApplication at interpreter exit,
+ # which segfaults. Delete it (and the model) while the app is still there.
+ self.addCleanup(self._delete, m, w)
w.show()
m.failure = failure
w._show_failure()
return m, w
+ def _delete(self, m, w):
+ w.close()
+ w.deleteLater()
+ m.deleteLater()
+ self.app.sendPostedEvents(None, QEvent.DeferredDelete)
+ self.app.processEvents()
+
def test_a_known_stop_shows_its_hint_and_the_buttons_it_has(self):
m, w = self._window(bf.Failure(bf.OTHER_METAL))
self.assertFalse(w.failure_box.isHidden())
diff --git a/frontend-qt/tests/test_win.py b/frontend-qt/tests/test_win.py
index c1206e48..e95e5ab4 100644
--- a/frontend-qt/tests/test_win.py
+++ b/frontend-qt/tests/test_win.py
@@ -1698,7 +1698,7 @@ class InstallFailureHintTest(unittest.TestCase):
# pure function, so its source is extracted and run standalone when Qt is absent.
try:
from nspb_qt import model as M
- classify = M.BuildModel._classify_install_failure
+ classify = M.Model._classify_install_failure
except ImportError:
import ast
src = (HERE.parent / 'nspb_qt' / 'model.py').read_text()