-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
pytest.main(...) hangs but works if run with subprocess.check_output #4434
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
Comments
If I run the command with --debug, here is the snippet of the trace where it hangs:
Essentially, it has reported that the worker (and the only test) is finished, but processing stops at that point until I kill the process. |
Does using |
|
The run hangs when I run with Python 2.7 (default on OSX). If I run on Python 3 it seems to work without modification. |
If run in series on Python 2 with debug, I get this trace:
It then hangs. |
hmmm didn't you see |
Ah, yes, that was the line just prior to "test session starts" |
Does that file exist in your machine? I was under the impression it would get written even if the process never finished. |
It does. I can send you the file for each case, one where is hangs on Python 2, and one where it succeeds in Python 3. Should I send it to the email in your profile? |
We also have CI builds where pytest hangs. They are on Python 2.7 and with pytest 4.0, see gammapy/gammapy#1940 (comment) . I tried setting |
I can reproduce the issue locally on MacOS with this conda env.yml like this:
pytest hangs forever at very high CPU load. This shows continued printout of such lines:
These commands should let you reproduce the issue locally. If needed, I could try to create a more minimal conda environment or docker image that shows the issue. It looks like pytest 4.0 has a serious issue under Python 2.7 for some environments, no? |
Please post it here in an issue, thanks (you can drag and drop the files to the issue text box directly) |
@cdeil thanks for posting a reproducible case, unfortunately I'm on Windows and I can't recreate your environment:
The Can you pass options to
Not sure if this is an issue with Python 2.7 specifically, nothing that came out in 2.7 comes to mind (we only changed some pytest warnings into errors, really). Also, what happens if you use |
@nicoddemus - Can you try this simpler env?
and then the same:
or
will hang.
Does this mean it collected the @nicoddemus - I'll try to follow your other suggestions locally. Maybe I should try to make a Docker image that has the issue, then you can execute it and have a look more easily? |
What's happening is that pytest calls pytest again: So it might not be connected to the issue reported by @tjprescott here originally, although it also sounds like you might be calling pytest recursively? I still don't know what to do here. Should |
@cdeil can you try with pytest 3.10? I ask because you have the environment on your hand so it should be simple to try it. pytest has been collected packages (and tests within them) for some time now (3.8? I think) so I want to know if the problem is related with that. |
With pytest 3.10 I get this, i.e. no tests are collected at all: With pytest 3.7, I get this AttributeError pytest 3.6 is the last version where it works. Still not sure what to do here. Maybe we should simply exclude |
@cdeil thanks a lot for testing things out. You are right, the problem seems to be with the fact that the test runner will start executing things when imported directly. Somewhere we need to add an Can you jump on Gitter real quick? I suspect we might be able to solve this quickly on chat. |
@cdeil and I figured the problem after some quick poking around: pytest since 3.8 collects Setting |
@nicoddemus - thank you for diagnosing this! |
@nicoddemus - You are awesome! @tjprescott - Are you also accidentally running pytest from pytest like we are? Or is it a different one? If the second, I am really sorry for derailing your issue report; I should have opened a separate issue. @astrofrog - I will send PRs with the one-line change for the Astropy and package-template repos. |
@cdeil I'm not sure what you mean by "running pytest from pytest". I was simply trying to call |
Here are the debug logs. |
Hi @tjprescott, Unfortunately the logs don't tell much, all hooks have been called in what seems to be the correct order. 😕 Given that you have found a workaround and we have ran out of ways to debug this, I propose we close this issue. |
Thanks. I'm sorry we couldn't get to the bottom of your problem. |
No worries. It's entirely possible I was just "doing it wrong". Thanks for looking into it. |
In my code, I call
pytest.main(arguments)
to run Pytest.This code hangs when run on OSX (10.14.1) but works fine on Windows.
If I change the last line to instead essentially call pytest through
subprocess.check_output
it executes fine. It also works if I simply copy-paste the command to my terminal. This behavior is observed whether I specify-n=auto
or not, which is why I'm posting this here instead of in pytest-xdist. Is there something I'm doing wrong here?Pip List
OS Info
The text was updated successfully, but these errors were encountered: