-1

Error discovering pytest tests,see Output -> Python screenshot

One strange thing I notice in the above screenshot is: it always has a "d" inside the search bar under Testing even I closed and re-open VSCode, you can see it from the screenshot above.

I checked pytest has been installed, screenshot

Here is the output content from Output -> Python. The "import pytest" error comes from the .vscode-server folder.

I am using VSCode 1.69.2, Windows 10 OS

LSP Notebooks experiment is disabled -- not in treatment group

python -c "import sys;print(sys.executable)" python -c "import sys;print(sys.executable)" Python interpreter path: /usr/local/bin/python python -c "import sys;print(sys.executable)" Starting Pylance language server. python -c "import sys;print(sys.executable)" python -c "import sys;print(sys.executable)" python -c "import sys;print(sys.executable)" python -c "import sys;print(sys.executable)" python ./.vscode-server/extensions/ms-python.python-2022.10.1/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear workflow cwd: . [ERROR 2022-6-26 13:1:2.338]: Error discovering pytest tests: [n [Error]: Traceback (most recent call last): File "/home/cdsw/.vscode-server/extensions/ms-python.python-2022.10.1/pythonFiles/testing_tools/run_adapter.py", line 17, in from testing_tools.adapter.main import parse_args, main File "/home/cdsw/.vscode-server/extensions/ms-python.python-2022.10.1/pythonFiles/testing_tools/adapter/main.py", line 9, in from . import pytest, report File "/home/cdsw/.vscode-server/extensions/ms-python.python-2022.10.1/pythonFiles/testing_tools/adapter/pytest/init.py", line 7, in from ._discovery import discover File "/home/cdsw/.vscode-server/extensions/ms-python.python-2022.10.1/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 8, in import pytest ImportError: No module named pytest

at ChildProcess. (/home/cdsw/.vscode-server/extensions/ms-python.python-2022.10.1/out/client/extension.js:2:232783) at Object.onceWrapper (node:events:510:26) at ChildProcess.emit (node:events:390:28) at maybeClose (node:internal/child_process:1064:16) at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)]

python -c "import sys;print(sys.executable)"

So as you can see that I have installed the pytest, but the .vscode-server still complains about it.

1 Answers1

0

The solution is to bring up the command palate and type: "Python: Select Interpreter" to select a running Python interpreter.

By default, the VSCode picked up a corrupted conda environment on my PC which caused this issue. I have created a PR for them and it has been assigned to sb.

Also there is another cause for this problem, in my case, our company has Python 3.6 which is not supported in the latest Python Extension for VSCode. Once I downgraded the Python Extension to older version which supports Python 3.6, the Unit Tests can be found again.