diff --git a/tests/PythonQtTestCleanup.cpp b/tests/PythonQtTestCleanup.cpp index d8d652fa2..c10681d1b 100644 --- a/tests/PythonQtTestCleanup.cpp +++ b/tests/PythonQtTestCleanup.cpp @@ -61,18 +61,18 @@ void PythonQtTestCleanup::testCallQtMethodInDestructorOwnedQTimer() void PythonQtTestCleanup::testCallQtMethodInDestructorWeakRefGuarded() { - QVERIFY(_helper->runScript( - "import weakref\n" \ - "import PythonQt.QtCore\n" \ - "class TimerWrapper(object):\n" \ - " def __init__(self):\n" \ - " self.timerWeakRef = weakref.ref(PythonQt.QtCore.QTimer())\n" \ - " def __del__(self):\n" \ - " if self.timerWeakRef():\n" \ - " self.timerWeakRef().setSingleShot(True)\n" \ - "x = TimerWrapper()\n" \ - "obj.setPassed()\n" - )); + QVERIFY(_helper->runScript( + "import weakref\n" \ + "import PythonQt.QtCore\n" \ + "class TimerWrapper(object):\n" \ + " def __init__(self):\n" \ + " self.timerWeakRef = weakref.ref(PythonQt.QtCore.QTimer())\n" \ + " def __del__(self):\n" \ + " if self.timerWeakRef():\n" \ + " self.timerWeakRef().setSingleShot(True)\n" \ + "x = TimerWrapper()\n" \ + "obj.setPassed()\n" + )); } void PythonQtTestCleanup::testSignalReceiverCleanup() @@ -81,11 +81,21 @@ void PythonQtTestCleanup::testSignalReceiverCleanup() // Test that PythonQtSignalReceiver is cleaned up properly, // i.e. PythonQt::cleanup() doesn't segfault - main.evalScript( + QVERIFY(_helper->runScript( "import PythonQt.QtCore\n" \ "timer = PythonQt.QtCore.QTimer(obj)\n" \ - "timer.connect('destroyed()', obj.onDestroyed)\n" - ); + "timer.connect('destroyed()', obj.onDestroyed)\n" \ + "obj.setPassed()\n" + )); +} + +void PythonQtTestCleanup::testPyFinalizeThenPythonQtCleanup() +{ + if (Py_IsInitialized()) { + Py_Finalize(); + } + + PythonQt::cleanup(); } bool PythonQtTestCleanupHelper::runScript(const char* script) diff --git a/tests/PythonQtTestCleanup.h b/tests/PythonQtTestCleanup.h index 82b14d547..c7e593e24 100644 --- a/tests/PythonQtTestCleanup.h +++ b/tests/PythonQtTestCleanup.h @@ -20,6 +20,7 @@ private Q_SLOTS: void testCallQtMethodInDestructorOwnedQTimer(); void testCallQtMethodInDestructorWeakRefGuarded(); void testSignalReceiverCleanup(); + void testPyFinalizeThenPythonQtCleanup(); private: PythonQtTestCleanupHelper* _helper;