VSCode pytest discovery not working: conda error?

Viewed 643

I'm having a strange problem with VSCode's python testing functionality. When I try to discover tests I get the following error:

> conda run -n sandbox --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.0.1786462952/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.0.1786462952/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear .
cwd: .
[ERROR 2022-1-3 21:49:47.851]: Error discovering pytest tests:
 [r [Error]: 
EnvironmentLocationNotFound: Not a conda environment: /Users/david.hoffman/miniconda3/envs/sandbox/envs/sandbox

But obviously there's a duplication error: /Users/david.hoffman/miniconda3/envs/sandbox/envs/sandbox.

If I run this command directly in the terminal I get the expected output and no errors:

conda run -n sandbox --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.0.1786462952/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.0.1786462952/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear

I'm completely stumped as there doesn't seem to be any settings that would affect this.

I tried reinstalling VSCode from scratch (after removing all the local files) same with conda.

2 Answers

Two ways I've found to fix:

  1. Change the name of the conda environment. Just cloning sandbox to boxsand did the trick
  2. Add python.condaPath variable to VSCode's preferences

FWIW, I ran into the same issue but found a different (easier?) solution.

Turns out I had conda installed within the conda environment. Uninstalling conda from the environment itself (mamba uninstall -n myenv conda) fixed it.

Lots of people have run into this, though, and there are active issues in both the VSCode and conda Githubs.

Related