qtbot in pytest-qt raising AttributeError

34 Views Asked by At

OS: W10
Python: 3.10
pytest: 7.3.1
pytest-qt: 4.2.0

It's some time since I've used the qtbot fixture. I have what I believe to be a simple setup here. In this code I have included the qtbot fixture in the test function:

def test_is_possible_to_log_a_message(qtbot):
    ...
    index_0_2 = log_table_view.model().createIndex(0, 2)
    with qtbot.wait(100):
        text_0_2 = log_table_view.model().data(index_0_2)
    assert ...

This is causing the following error:

>       with qtbot.wait(100):
E       AttributeError: __enter__

... I can't see any sign of others experiencing this with pytest-qt. Anyone got any ideas what the problem might be?

Update
I was also getting a (more familiar) error when I instead used waitUntil (by the way, here, following a signal being emitted, I'm waiting for some text to appear in a cell of a QTableView):

def text_obtained():
    text_0_2 = log_table_view.model().data(index_0_2)
    print(f'text_0_2 |{text_0_2}|')
    assert text_0_2 != None 
    
qtbot.waitUntil(text_obtained)    

I was getting, on the first call to text_obtained:

>       text_0_2 = log_table_view.model().data(index_0_2)
E       RuntimeError: wrapped C/C++ object of type LogTableView has been deleted

... but I've now found that by calling show() on my QMainWindow (NB nothing appears as I'm using QT_QPA_PLATFORM = offscreen) and by using waitUntil for elements to become visible, this no longer happens.

However, the AttributeError is still happening on wait...

0

There are 0 best solutions below