Open adam-grant-hendry opened 2 years ago
Hi @adam-grant-hendry,
TBH I didn't even know you can run in headless mode on Windows. Any reason why you are doing that? I ask because AFAIK even in CI machines Windows is always in "head" mode.
@nicoddemus I want to run in headless mode for the same reason as Linux and MacOS users, who have pytest-xvfb
for their purposes (see my "Similar Requests" section below).
What I don't understand is that if I run test_toolbar_statusbar_and_tooltip_messages
alone, it works both in windows and headless modes:
pytest ./tests/test_view.py::test_toolbar_statusbar_and_tooltip_messages
but the minute I add another test that uses qtbot
, the test for QtWidgets.QToolTip.text() == 'New Project'
fails (times out), but just that test. The statusbar messages test works fine. I can even repeat the test test_menubar_statusbar_messages
by copying-pasting and making a test_menubar_statusbar_messages_02
and both tests pass, but the test_toolbar_statusbar_and_tooltip_messages
fails with the QToolTip test.
This tells me the test works in both modes, but something is happening with qtbot
that is creating an error.
If you do run in windowed mode on a local runner, note that one does need to run
root.view.setWindowFlags(
QtCore.Qt.Window | QtCore.Qt.CustomizeWindowHint | QtCore.Qt.WindowStaysOnTopHint
)
before calling
root.view.show()
otherwise tests will fail because the window might not have focus if you are working in another window.
@nicoddemus @The-Compiler Are you able to repeat these results on your machine(s)?
It would be interesting to see if users of pytest-qt
with pytest-xvfb
run into this isssue.
TBH I didn't even know you can run in headless mode on Windows.
@nicoddemus Your tox.ini
has QT_QPA_PLATFORM=offscreen
😄
[tox]
envlist = py{37,38,39,310}-{pyqt5,pyside2,pyside6,pyqt6}, linting
[testenv]
...
setenv=
...
QT_QPA_PLATFORM=offscreen
Yes, but I thought it only had an effect on Linux.
Yes, but I thought it only had an effect on Linux.
Oh I see. No, it does in fact have an effect on Windows as well.
I use GitLab for CI and need to test my PyQt5 GUI in headless mode with
pytest-qt
(I use python 3.8 on Windows 10). To that end, I can run in headless mode by setting the environment variableQT_QPA_PLATFORM
to"offscreen"
in mypyproject.toml
:and the following test passes when run in windowed mode, but the tooltip test fails in headless mode (regardless of whether I use
qtbot.waitUntil
or a simpleqtbot.wait
). How can I make this pass in headless mode?:tests/test_view.py
Here is the remaining code for the MRE:
tests/conftest.py
myproj/main.py
Results
Here is the error message I receive in headless mode:
Update
I also run a similar test for my menubar items and found if I didn't run this that the test does pass in headless mode. I wonder if there is something wrong with my fixtures...
Update
If I attempt to use
setMouseTracking(True)
and only usemouseMove
, I get these warning messages (otherwise, I just get theThis plugin does not support propagateSizeHints()
warning):Also, I seem to get a segfault:
ASIDE:
(I typically suppress these messages with
-p no:faulthandler
to[tool.pytest.ini_options]
; see pytest - Windows fatal exception: code 0x8001010):Additional
Further information here on the
QtWarningMsg
I receive thatThis plugin does not support propogateSizeHints()
.