question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

application changes persist through tests, qtbot.mouseClick() not working on sample test application

See original GitHub issue

Apologies in advance for reporting two issues at the same time, but I figured it would be messier to have two tracked issues with mostly identical contents.

Application changes persist through tests

This is the main issue that I am encountering on the application I am developing. The application automatically stores UI changes through QSettings, for this reason I have made a fixture with autouse=True that unsets $HOME so that no configuration is saved. I have been able to confirm through strace that no configuration is saved to disk by QSettings this way.

Furthermore I have made a fixture with a function scope that instances the window, yields and then closes it. Regardless, when qtbot clicks something, the effect of that click is brought to the subsequent tests. A test toggles an option, which causes another test that expects the application to be in its default state to fail.

I have created a PoC file with a simple application containing just a checkbox that saves state through QSettings, and two tests that click the same checkbox: test.py.txt

qtbot.mouseClick() not working on sample test application

While it works on the real application I am developing, qtbot seems to not work in the PoC that I made for this bug report even though I cannot see any substantial difference in the two codes.

The sample application has a handler linked to the checkbox that logs on a file whenever it’s triggered. This never happens when qtbot sends the click, but when I do it in the stopForInteraction() segment it works as it should.

Chances are I am overlooking something stupid, but despite my best efforts I cannot see anything that would warrant the malfunction.


Even though I cannot get qtbot to work properly, I could still reproduce the first issue - when I click the checkbox during the stopForInteraction() of the first test, the checkbox state is preserved on the second stopForInteraction() part.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
adamgranthendrycommented, Aug 9, 2021

@nicoddemus, @xstasi, & @The-Compiler, please see the answers to my StackOverflow questions as they may help you and future users with the same problem(s):

  1. pytest-qt Function mouseMove() Not Working

  2. pytestqt.mouseMove to menubar menu widget moves to wrong place

0reactions
nicoddemuscommented, Aug 9, 2021

Thanks for the links!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reference — pytest-qt documentation - Read the Docs
with qtbot.capture_exceptions() as exceptions: qtbot.click(button) ... Stops the current test flow, letting the user interact with any visible widget.
Read more >
How to click on QMessageBox with pytest-qt? - Stack Overflow
In your attempt you are creating a new QMessageBox that is different from the one created with the static method QMessageBox::question() so ...
Read more >
PyDev adventures: 2014
QApplication.instance() if app is None: app = QtGui. ... default to all tests by using autouse=True to make sure no test has such...
Read more >
TestCase QML Type | Qt Quick Test 6.4.1
The problem with this pattern is that any failures in the test function will cause the ... Multiple TestCase types can be supplied...
Read more >
Quick start into GUI applications with PyQt5 and PySide2
You may find a lot of tutorials for PyQt due to it age. PyQt4 is the former main version while now we use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found