vscode-python: Pytest discovery fails if something is printed to stderr
Can I get any help with pytest discovery failure?
> /usr/local/bin/python ~/.vscode-server/extensions/ms-python.python-2022.0.1786462952/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear
cwd: .
[ERROR 2022-1-3 23:36:9.283]: Error discovering pytest tests:
[r [Error]: Graceful shutdown completed in 0.000 seconds.
at ChildProcess.<anonymous> (/root/.vscode-server/extensions/ms-python.python-2022.0.1786462952/out/client/extension.js:32:39235)
at Object.onceWrapper (events.js:422:26)
at ChildProcess.emit (events.js:315:20)
at maybeClose (internal/child_process.js:1048:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5)]
Tried many different options with “python.testing.cwd” and “python.testing.pytestArgs” but without luck.
I used unit tests in the past and they work fine in VS Code.
Also I use VS Code with “Remote Container” and work inside the Docker container and run tests inside it.
Hope that you can solve this issue soon, because with pytest it doesn’t work for me. And I have no clear vision why. Thanks.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 8
- Comments: 31 (1 by maintainers)
Getting a similar error, however it seems like it’s because the environment location is messed up
I’m getting a very similar issue - pytest discovery not working in vscode while pytest from cmd line works fine. From the code Python output I see:
Not sure if something in conda is able to interpret
~\.vscode\extens...
as%userprofile%\.vscode\extens...
(I’m running on Windows where “~” doesn’t resolve to anything).If I try to copy that command (and replace the “~” with userprofile path), it fails as follows
(I’ve added -v flags to conda run to try to get more info):
I also tried removing the
get_output_via_markers.py
component of the command - still no success. But I noticed that it seemed to be trying to execute pytest from the conda base environment rather than the current conda env.This is the line I’m referring to - although not sure if this is a anything to do with the problem - it should be f:\anaconda\envs\msticpy\python.exe
The result is the same with or without the
-v
flags.I digged in this problem because I was using the
environment.yml
to set env variables and I discoverd the following:the problem semms to be to me that that
conda
puts a message on thestderr
:Then
vscode-python
everytime founds a new message on thestderr
, forwards itIn this case, I guess is conda’s fault since it writes to the
stderr
this WARNINGBtw, if vscode would activate the environment before, instead of running:
The problem would be fixed
Mine is working again seemingly… I’ll open up a new issue if it returns
Edit: ah ok, I think I’ve discovered the source of the error, will open a new issue. Edit2: Opened as #19090
@kimadeline https://github.com/microsoft/vscode-python/issues/19069
Update:
Thanks!
@1vecera For now I “fixed” the issue by reverting to
v2021.12.1559732655
There’s a fundamental issue here in that the extension is always trying to do full discovery before anything is usable/runnable.
In large repositories this is impractical, unhelpful, time-consuming, and unnecessary. I appreciate this might be due to our repository structure choices, but in a repository such as ours with a 10-year history and many, many sub-folders this is hugely impractical and almost unusable.
With e.g. Eclipse and PyDev I can always select a test file or folder and “just run it” regardless of the state of the rest of the repo. This doesn’t seem that unreasonable, or that unachievable. With a large repo, I largely don’t care about the state of the rest of the repo, I just want to run the test/tests I’m currently working on.
Ultimately, if the the file I’m viewing is called test.py and the function I’m looking at is called test I should be able to run it, without caring about anything else, shouldn’t I?
Hi everyone, a couple of things here:
python=3.XXX
argument, or the extension won’t recognize it as a conda environment;.env
file.@1st and @brianoflondon, please provide a sample repo that I can use to try and replicate your issues.
Perhaps I’m getting something similar which seems to stem from the discovery process trying to run my module itself with bad command line options. I’m really new to setting up a new project here so very unsure if this is my problem or similar to what others have reported here.
This bit puzzles me, why is discovery trying to run
podping-hivewatcher
(my project) with pytest command line options.Running
pytest
on the command line works fine.