-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Test discovery fails if package is not installed #10469
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
Unfortunately this is a shortcoming/design of pytest as it imports code to do its test discovery and we need pytest to tell us what tests there are and where those tests are. So for us to do this would require pytest updating their test discovery to not require importing code to detect tests. |
Running pytest on its own doesn't result in the same error, it's only when executed via the vscode extension. For example, if you run
|
@RobTheFiveNine we will have a look! |
Hi @RobTheFiveNine , thank you for reaching out. I was able to replicate your issue with the sample repo and steps you provided, so thank you for that as well, they were very helpful! 👉 Instead of having to install the project as a package, adding an 📋 NotesWhen running Running the PVSC command fails, but running the equivalent command works: Adding @brettcannon something to do about how |
@kimadeline just tried your suggestion of adding |
@kimadeline it possibly does, but it might also just be pytest since our discovery is run as a plug-in to pytest while also launching it. Question is whether we consider it a bug or more of a feature enhancement. |
Fair enough, I'll mark it as an enhancement and "needs decision" for now. |
I'm facing the same issue. I have this structure:
So, I have Another option might be capturing the output of |
@mahmoudajawad we aren't reading pytest output, actually. We inject a pytest plug-in that gets run as part of discovery and use that to do the recording of what tests exist. |
@brettcannon, I see. That makes sense. I'll try to look on what's going on and see if I can patch it to make it record tests even if pytest fail. |
UPDATE: nvm, I found at it:
@brettcannon, can you direct me to where is the plugin that is being injected? I couldn't figure it out myself through the quick scan of the structure being offered in this extension. |
dup of #13301 which has just been fixed and is insiders. |
Environment data
"python.jediEnabled"
set to; more info How to update the language server to the latest stable version #3977):false
python.languageServer
setting:Microsoft
Expected behaviour
When launching vscode, the tests from the
tests/
directory should be discovered successfully; regardless of whether the project has been installed as a package.Actual behaviour
Import errors are thrown out in the output tab and test discovery fails.
Example output:
Running pytest separately, with the same launch arguments works fine in a terminal window, but when executed using vscode's test discovery function, it fails to import unless the project is installed as a package first (i.e. by running
python setup.py install --record record.txt
)Steps to reproduce:
virtualenv venv -p python3
source venv/bin/activate
pip install pytest
python -m pytest
in the project directorypython setup.py install --record record.txt
to install the project as a package in the venv, and then click on the tests label in the status bar or relaunch vscode, to find that vscode now discovers the tests successfullyLogs
The text was updated successfully, but these errors were encountered: