Please note: this is on W10. This may well be significant.
Python: 3.9.4 pytest: 6.2.5 pytest-qt: 4.0.2
I've been using pytest-qt for about a week now to start developing a PyQt5 app. There have been a few baffling problems but none as baffling as this one.
My app code:
class LogTableView(QtWidgets.QTableView):
def __init__(self, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
def resizeEvent(self, resize_event):
super().resizeEvent(resize_event)
# self.resizeRowsToContents()
The last line above needs to be added. Using a TDD approach I therefore start writing the test:
def test_resize_event_should_result_in_resize_rows(request, qtbot):
t_logger.info(f'\n>>>>>> test name: {request.node.originalname}')
table_view = logger_table.LogTableView(QtWidgets.QSplitter())
# with unittest.mock.patch.object(table_view, 'resizeRowsToContents') as mock_resize:
# with unittest.mock.patch('logger_table.LogTableView.resizeRowsToContents') as mock_resize:
table_view.resizeEvent(QtGui.QResizeEvent(QtCore.QSize(10, 10), QtCore.QSize(20, 20)))
NB the commented-out lines show the kind of things I have been trying. But you can see that even just creating an object of the type LogTableView
, and then calling the method, with no mocks around at all, causes the error.
On running this:
>pytest -s -v -k test_logger_table.py
I get this:
...
self = <logger_table.LogTableView object at 0x000002B672697670>
resize_event = <PyQt5.QtGui.QResizeEvent object at 0x000002B672743940>
def resizeEvent(self, resize_event):
> super().resizeEvent(resize_event)
E RuntimeError: wrapped C/C++ object of type LogTableView has been deleted
...
Has anyone got any idea what this is about?
PS FWIW, out of despair, I even tried this:
super(LogTableView, self).resizeEvent(resize_event)
... same error.