[PyQt] mem leak when testing PyQt with pytest

oliver oliver.schoenborn at gmail.com
Tue Nov 8 14:09:20 GMT 2016

*The following pytest test leaks memory (the memory and other kernel
objects like GDI and User handles keep increasing at every iteration and
never go back down until test exits): import pytest from PyQt5.QtCore
import QTimer from PyQt5.QtWidgets import QApplication, QGraphicsScene,
QGraphicsView class TestCase: @pytest.mark.parametrize('dummy',
range(1000)) def test_empty(self, dummy): # self.view = None # does NOT fix
the leak if uncommented! self.app = QApplication.instance() if self.app is
None: self.app = QApplication([]) self.view = QGraphicsView()
self.view.setFixedSize(600, 400) self.view.setScene(QGraphicsScene())
self.view.show() QTimer.singleShot(100, self.app.exit) self.app.exec() #
self.view = None # FIXES the leak if uncommented!*

*Leak stops if last line is uncommented, but this sort of fix is
error-prone solution as every developer has to remember to do this for each
test. There are a couple other ways of stopping the leak and creating the
leak, details are in my post at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20161108/a0df392a/attachment.html>

More information about the PyQt mailing list