Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvocationError when testing via tox but not via pytest called directly #170

Closed
ixjlyons opened this issue May 11, 2017 · 10 comments
Closed

Comments

@ixjlyons
Copy link

I've set up a minimally reproducible example as a repo here. The README explains how I've invoked the test using pytest directly and with tox, and I can't figure out why it doesn't work with tox.

If I've made an obvious error in my tox.ini somewhere, I'd appreciate finding out what to fix. This is the only place in the tox code that prints out the InvocationError without any other information except the command in question (what I'm seeing).

It should also be noted that I can run pytest-qt's tests with tox just fine. Also, if I comment out the test function's contents and remove the use of the qtbot fixture, the test runs fine with tox.

@The-Compiler
Copy link
Member

The-Compiler commented May 11, 2017

Does adding passenv = * under [testenv] change anything? Can you install the pytest-faulthandler plugin and run pytest with -s and see if that gives you anything useful?

edit: My best guess would be that passenv = DISPLAY fixes this

@ixjlyons
Copy link
Author

passenv = DISPLAY XAUTHORITY seems to do the trick (both required). Should a note about using pytest-qt with tox (I'm assuming also it's Linux-specific) be added to the docs?

@The-Compiler thanks a lot for the quick help by the way. This issue has irritated me for months and I only now put in a bit of time to produce a demo to try and get it resolved.

@The-Compiler
Copy link
Member

You'll either need to do that or install pytest-xvfb then.

Unfortunately, Qt simply calls abort() on that error, and pytest's output capturing can't show the error to you as the process was just killed.

There's really not much we can do about this... I wonder if it'd help if pytest-qt disabled the output capturing while creating the QApplication though.

@nicoddemus
Copy link
Member

@ixjlyons perhaps we can add a "Troubleshooting" sections to the docs, where we can mention both the "tox passenv" solution and the "abort()" issue?

@cauveryguda
Copy link

I am facing the same issue with tox. Tried placing passenv = DISPLAY XAUTHORITY under testenv in tox.ini but that did not help. Did your help on fixing this.

@The-Compiler
Copy link
Member

@cauveryguda Is that with pytest? Can you run pytest with -s and see what's printed?

@reinjunon
Copy link

I have a similar problem. When running it live, your @The-Compiler your suggestion for passenv works. However, if i plan to integrate the test in the backend through jenkins, it fails with no error displayed.
ERROR: InvocationError for command '/var/lib/jenkins/workspace/se_thenewgui/.tox/py36/bin/pytest' (exited with code 1)

@The-Compiler
Copy link
Member

Like I said above, you need a display server (or something like pytest-xvfb) to be able to run graphical PyQt applications.

@dvdblk
Copy link

dvdblk commented Jun 2, 2021

Came across this issue without using QT. This error pops up when you have no tests defined in your test.py files.

Simply running pytest results in

$ pytest
========================================== test session starts ==========================================
platform linux -- Python 3.8.3, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: 
plugins: anyio-2.2.0, web3-5.19.0
collected 0 items                                                                                       

========================================= no tests ran in 0.01s =========================================
$

Running tox with a simple command = pytest setup results in:

========================================== test session starts ==========================================
platform linux -- Python 3.8.2, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
cachedir: .tox/python/.pytest_cache
rootdir: 
collected 0 items                                                                                       

========================================= no tests ran in 0.01s =========================================
ERROR: InvocationError for command ./.tox/python/bin/pytest (exited with code 5)
________________________________________________ summary ________________________________________________
ERROR:   python: commands failed

After defining at least one test function in tests/*.py the error no longer pops up.

@nicoddemus
Copy link
Member

Hi @dvdblk,

That's standard pytest behavior: if it cannot find any test files, it will exit with error code 5, not related to pytest-qt at all.

oczkoisse added a commit to oczkoisse/numbat that referenced this issue Sep 4, 2021
Qt applications need a display server to run and be tested. tox
will not pass necessary environment variables from invocation
environment by default. For tests to run, these variables must be
passed in tox configuration explicitly. For more information, see
pytest-dev/pytest-qt#170 and
pytest-dev/pytest-qt#324
agoscinski added a commit to osscar-org/scicode-widgets that referenced this issue Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants