I spent ages trying to decipher this unhelpful error after creating a test that had import errors. Verify that your test suite can actually be executed before doing any deeper troubleshooting.
pytest --collect-only is your friend.
I spent ages trying to decipher this unhelpful error after creating a test that had import errors. Verify that your test suite can actually be executed before doing any deeper troubleshooting.
pytest --collect-only is your friend.
This is not a complete answer as I do not know why this is happening and may not relate to your problem, depending how you have your tests structured.
I resolved this issue by putting an __init__.py file in my tests folder
E.G.:
├───.vscode
│ settings.json
│
├───app
│ myapp.py
│
└───tests
test_myapp.py
__init__.py
this was working a few days ago without this but the python extension was recently updated. I am not sure if this is the intended behavior or a side effect of how discoveries are now being made
https://github.com/Microsoft/vscode-python/blob/master/CHANGELOG.md
Use Python code for discovery of tests when using pytest. (#4795)
I am working on a data science project and my project tree looks like this:
data/ notebooks/ scripts/ utils/ - __init__.py - utils1.py - utils2.py - utils3.py - utils4.py - tests/ -- test_utils1.py -- test_utils2.py -- test_utils3.py -- test_utils4.py
I import functions I wrote in utils1.py, utils2.py, etc. to reuse throughout my notebooks and scripts. To run the tests for these, I cd into utils/ and then run python -m pytest from the terminal, which works fine.
I saw that there is a beaker icon for testing in VSCode, but my tests are not being discovered:
screenshotContents of __init__.py look a little like this:
from utils.utils4 import foo, barfrom .utils1 import foo2, bar2from .utils2 import function1, function2from .utils3 import *
See the comment below for Output.
It breaks my flow to switch to the terminal each time I modify a utility function to verify tests are passing. How should I configure VSCode to make better use of the Test Explorer?
Update: see my comment for the solution
Python Test Discovery Failed with no error message
Test discovery error with pytest
Pytest discovery fails
VSCode cannot detect pytest unit tests, even pytest has been installed, error comes from inside .vscode-serve folder, behind company's proxy
Videos
pytest works from the command line, therefore it is installed correctly (I use Anaconda). But within VS Code I simply cannot get it to work. In the log, I get this error:
python c:\Users\renan\.vscode\extensions\ms-python.python-2021.2.636928669\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir c:\Users\renan\Documents\Sources\Python-6502 -s --cache-clear Test Discovery failed: TypeError: Cannot read property 'uri' of undefined
My settings.json is:
{
"python.testing.cwd": ".",
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"python.pythonPath": "C:\\ProgramData\\Anaconda3\\python.exe"
}Python version is 3.8.5, I am using the Python extension from the repo and my VSCode version is:
Version: 1.54.1 (user setup) Commit: f30a9b73e8ffc278e71575118b6bf568f04587c8 Date: 2021-03-04T22:38:31.419Z (5 days ago) Electron: 11.3.0 Chrome: 87.0.4280.141 Node.js: 12.18.3 V8: 8.7.220.31-electron.0 OS: Windows_NT x64 10.0.19042
What am I missing?