Skip to content

Test discovery with pytest fails, because pytest is run in the base conda env #24122

Closed

Description

Type: Bug

Behaviour

Test discovery with pytest fails.

From looking at the output, it seems that pytest is run in my base conda environment, not in the environment for this particular project. My base conda environment has an old, no longer supported Python version and no pytest installed; however, a recent version of python and pytest are installed in the environment that I use for this project and that I want to run the tests in.

I verified that "Python: Select Interpreter ..." is set to the correct environment and this is confirmed by the little icon on the status bar at the bottom right that displays "Python 3.11.7 ('sherpaciao')", where "sherpaciao" is a conda env with pytest. Running pytest in the terminal in that conda env works as extected.

Note that the condo env in the Python output (see full output below) is set to "CONDA_PREFIX":"/Users/guenther/mambaforge","CONDA_PROMPT_MODIFIER":"(base) while the warning a few lines down from that addresses the correct conda env: [warning] could not find a pixi interpreter for the interpreter at /Users/guenther/mambaforge/envs/sherpaciao/bin/python.

Steps to reproduce:

I hope that this can be debugged from the console/setting output since it's probably related to some setting that is wrong; I suspect that it's not easy to reproduce.

Diagnostic data

Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)

2024-09-17 11:53:33.212 [info] Discover tests for workspace name: sherpa - uri: /Users/guenther/code/sherpa
2024-09-17 11:53:33.212 [info] Running discovery for pytest using the new test adapter.
2024-09-17 11:53:33.213 [info] All environment variables set for pytest discovery: {"ADS_API_TOKEN":"WPnK3GVwUCbcUvZzM2JcvKAkngy9lg2DPNS8Ss3A","COMMAND_MODE":"unix2003","CONDA_DEFAULT_ENV":"base","CONDA_EXE":"/Users/guenther/mambaforge/bin/conda","CONDA_PREFIX":"/Users/guenther/mambaforge","CONDA_PROMPT_MODIFIER":"(base) ","CONDA_PYTHON_EXE":"/Users/guenther/mambaforge/bin/python","CONDA_SHLVL":"1","DISPLAY":"/private/tmp/com.apple.launchd.T5UouRP3vi/org.xquartz:0","HOME":"/Users/guenther","LOGNAME":"guenther","MallocNanoZone":"0","OLDPWD":"/","ORIGINAL_XDG_CURRENT_DESKTOP":"undefined","PS1":"(base) %m %~> ","PWD":"/","SHELL":"/bin/zsh","SHLVL":"0","SSH_AUTH_SOCK":"/private/tmp/com.apple.launchd.9lE2FhSB4I/Listeners","TMPDIR":"/var/folders/r7/f0qh27rn207bwwvt3s7v5gh40000gn/T/","USER":"guenther","VSCODE_AMD_ENTRYPOINT":"vs/workbench/api/node/extensionHostProcess","VSCODE_CODE_CACHE_PATH":"/Users/guenther/Library/Application Support/Code/CachedData/38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40","VSCODE_CRASH_REPORTER_PROCESS_TYPE":"extensionHost","VSCODE_CWD":"/","VSCODE_HANDLES_UNCAUGHT_ERRORS":"true","VSCODE_IPC_HOOK":"/Users/guenther/Library/Application Support/Code/1.93-main.sock","VSCODE_NLS_CONFIG":"{\"userLocale\":\"en-us\",\"osLocale\":\"en-us\",\"resolvedLanguage\":\"en\",\"defaultMessagesFile\":\"/Applications/Visual Studio Code.app/Contents/Resources/app/out/nls.messages.json\",\"locale\":\"en-us\",\"availableLanguages\":{}}","VSCODE_PID":"83602","XPC_FLAGS":"0x0","XPC_SERVICE_NAME":"application.com.microsoft.VSCode.82204521.82204529","XUVTOP":"/Users/guenther/data/CHIANTI","_":"/Applications/Visual Studio Code.app/Contents/MacOS/Electron","__CFBundleIdentifier":"com.microsoft.VSCode","__CF_USER_TEXT_ENCODING":"0x1F5:0x0:0x0","ELECTRON_RUN_AS_NODE":"1","VSCODE_L10N_BUNDLE_LOCATION":"","PATH":"/Users/guenther/mambaforge/bin:/Users/guenther/mambaforge/condabin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Library/Apple/usr/bin:/Library/TeX/texbin","PYTHONPATH":"/Users/guenther/.vscode/extensions/ms-python.python-2024.14.1-darwin-arm64/python_files","TEST_RUN_PIPE":"/var/folders/r7/f0qh27rn207bwwvt3s7v5gh40000gn/T/python-test-discovery-331c548a6db514ee3062.sock"}
2024-09-17 11:53:33.214 [warning] could not find a pixi interpreter for the interpreter at /Users/guenther/mambaforge/envs/sherpaciao/bin/python
2024-09-17 11:53:33.216 [info] > python -m pytest -p vscode_pytest --collect-only
2024-09-17 11:53:33.216 [info] cwd: .
2024-09-17 11:53:33.272 [error] /Users/guenther/mambaforge/bin/python: No module named pytest

2024-09-17 11:53:33.275 [error] Subprocess exited unsuccessfully with exit code 1 and signal null on workspace /Users/guenther/code/sherpa.
2024-09-17 11:53:33.275 [error] Subprocess exited unsuccessfully with exit code 1 and signal null on workspace /Users/guenther/code/sherpa. Creating and sending error discovery payload
2024-09-17 11:53:33.275 [error] pytest test discovery error for workspace:  /Users/guenther/code/sherpa 
  
 The python test process was terminated before it could exit on its own, the process errored with: Code: 1, Signal: null for workspace /Users/guenther/code/sherpa
2024-09-17 12:07:41.517 [info] Native locator: Refresh started
2024-09-17 12:07:41.559 [info] Conda environment manager found at: /Users/guenther/mambaforge/bin/conda
2024-09-17 12:07:41.739 [info] Native locator: Refresh finished in 199 ms

Extension version: 2024.14.1
VS Code version: Code 1.93.1 (Universal) (38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40, 2024-09-11T17:20:05.685Z)
OS version: Darwin arm64 23.6.0
Modes:

  • Python version (& distribution if applicable, e.g. Anaconda): 3.11.7
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
  • Value of the python.languageServer setting: Default
User Settings


languageServer: "Pylance"

testing
• pytestEnabled: true

Installed Extensions
Extension Name Extension Id Version
Code Spell Checker streetsidesoftware.code-spell-checker 3.0.1
GitHub Actions github.vscode-github-actions 0.26.5
GitHub Copilot GitHub.copilot 1.229.0
GitHub Copilot Chat GitHub.copilot-chat 0.20.1
GitHub Pull Requests GitHub.vscode-pull-request-github 0.96.0
GitLens — Git supercharged eamodio.gitlens 15.5.1
JavaScript Debugger ms-vscode.js-debug 1.93.0
JavaScript Debugger Companion Extension ms-vscode.js-debug-companion 1.1.3
Jupyter ms-toolsai.jupyter 2024.8.1
Jupyter Cell Tags ms-toolsai.vscode-jupyter-cell-tags 0.1.9
Jupyter Keymap ms-toolsai.jupyter-keymap 1.1.2
Jupyter Notebook Renderers ms-toolsai.jupyter-renderers 1.0.19
LaTeX Workshop James-Yu.latex-workshop 10.3.2
Live Server ritwickdey.LiveServer 5.7.9
LTeX – LanguageTool grammar/spell checking valentjn.vscode-ltex 13.1.0
Makefile Tools ms-vscode.makefile-tools 0.11.13
Pylance ms-python.vscode-pylance 2024.9.1
Python ms-python.python 2024.14.1
Python Debugger ms-python.debugpy 2024.10.0
Table Visualizer for JavaScript Profiles ms-vscode.vscode-js-profile-table 1.0.9
Trailing Whitespace jkiviluoto.tws 1.0.1
System Info
Item Value
CPUs Apple M1 (8 x 2400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) 4, 3, 3
Memory (System) 16.00GB (0.09GB free)
Process Argv --crash-reporter-id e2a97932-7d55-44e5-bb05-555f7819c1cd
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
welcomedialogc:30910334
pythonnoceb:30805159
asynctok:30898717
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
accentitlementsc:30995553
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
bdiig495:31013172
a69g1124:31058053
dvdeprecation:31068756
dwnewjupytercf:31046870
newcmakeconfigv2:31071590
impr_priority:31102340
nativerepl1:31139838
refactort:31108082
pythonrstrctxt:31112756
flightc:31134773
wkspc-onlycs-t:31132770
nativeloc1:31134641
wkspc-ranged-c:31125598
cf971741:31134768
pme_test_t:31118333
defaultse:31133495
ei213698:31121563
iacca1:31138162

Activity

  1. eleanorjboyd commented on Sep 23, 2024

    @eleanorjboyd

    Hi! So to confirm, If you run python -m pytest --collect-only from your command line it works fine bc it has the right interpreter selected? Then secondly this path is the old one? Where it is looking for the pytest module: /Users/guenther/mambaforge/bin/python: No module named pytest. Thanks

  2. hamogu commented on Sep 23, 2024

    @hamogu
    Author

    Hi! So to confirm, If you run python -m pytest --collect-only from your command line it works fine bc it has the right interpreter selected?

    Yes.

    Then secondly this path is the old one? Where it is looking for the pytest module: /Users/guenther/mambaforge/bin/python: No module named pytest.

    Yes.

  3. eleanorjboyd commented on Sep 23, 2024

    @eleanorjboyd

    besides "CONDA_PREFIX":"/Users/guenther/mambaforge","CONDA_PROMPT_MODIFIER":"(base) any other notable settings? Anthony Kim (@anthonykim1) I am using the createActiveEnvironment command like this, any thoughts on how to produce more logging or what else could be going wrong? If not I can make a change to add additional logging to look at this

  4. hamogu commented on Sep 23, 2024

    @hamogu
    Author

    Except for conda, there should be nothing special going in that session. I should not that it's also not the first time that I see this, but I finally got annoyed enough to file an issue.
    That means it's not something that is special to this conda environment: VSCode always tries to run purest in my base environment.

  5. anthonykim1 commented on Sep 23, 2024

    @anthonykim1

    Don't think

    [warning] could not find a pixi interpreter for the interpreter at /Users/guenther/mambaforge/envs/sherpaciao/bin/python
    

    is related to this issue.

    Eleanor Boyd (@eleanorjboyd) It may be the ordering of:

    const condaExecutionService = await this.createCondaExecutionService(pythonPath, processService);
    if (condaExecutionService) {
    return condaExecutionService;
    }
    const env = createPythonEnv(pythonPath, processService, this.fileSystem);
    return createPythonService(processService, env);

    where createActivatedEnvironment just returns on the conda conditional without getting to the desired

    const env = createPythonEnv(pythonPath, processService, this.fileSystem);
    

    in this scneario. This seem the closest to what is "forcing" the use of conda rather than a desired venv?? in this case.

  6. hamogu commented on Sep 23, 2024

    @hamogu
    Author

    To the best of my knowledge (from googling all parts of this error message) [warning] could not find a pixi interpreter for the interpreter at /Users/guenther/mambaforge/envs/sherpaciao/bin/python is unrelated (I think from the IPython notebook extension). It's only relevant here in that it shows that at least some extensions are looking in the right place for the Python interpreter.

  7. 17 remaining items

  8. zljubisic commented on Oct 13, 2024

    @zljubisic

    Anthony Kim (@anthonykim1) please open this issue because it is not closed at all

  9. zljubisic commented on Oct 13, 2024

    @zljubisic

    Eleanor Boyd (@eleanorjboyd) let's continue on this.

  10. jcharlet commented on Oct 14, 2024

    @jcharlet

    Hi all,
    I confirm I have this issue :( and this isn't very pleasant.

    zljubisic Hans Moritz Günther (@hamogu), do you guys have a workaround for running the tests in VS Code? Is there anything better than running it from the terminal?

  11. ktmud commented on Oct 14, 2024

    @ktmud

    Still seeing this issue, too, after upgrading the python in my python env from py3.9 to py3.10

    Fixed this by re-installing vscode.

  12. wohenbushuang commented on Oct 15, 2024

    @wohenbushuang

    Seems it has been fixed in v2024.17.2024101501 (pre-release)

  13. jcharlet commented on Oct 17, 2024

    @jcharlet

    Argh, I tried reinstalling, even tried the Insiders version, but I had no luck, this is still happening.

  14. wohenbushuang commented on Oct 17, 2024

    @wohenbushuang

    Jeremie Charlet (@jcharlet) It is irrelevant with vscode insider. You should switch the python extension to pre-release version.

  15. tvatter commented on Oct 17, 2024

    @tvatter

    Same issue, super annoying

  16. anthonykim1 commented on Oct 17, 2024

    @anthonykim1

    Hi folks, please give the latest pre-release of Python extension (or v2024.17.2024101501 or higher) a try.
    This is unrelated to insider or vs code version itself.

  17. zljubisic commented on Oct 17, 2024

    @zljubisic

    Yes, there is a solution for it. I am using wsl, so I opened settings and looked for wsl python locator option and set it to "js".
    Default "native" doesn't work.

    Image

  18. dobos commented on Dec 5, 2024

    @dobos

    I'm having a related issue. I'm working on a machine with multiple anaconda installations and vscode seems to query them at startup using the "native" locator. This is what appears in the output log:

    2024-12-05 16:59:42.824 [info] Experiment 'pythonRecommendTensorboardExt' is active
    2024-12-05 16:59:42.824 [info] Experiment 'pythonSurveyNotification' is active
    2024-12-05 16:59:42.824 [info] Experiment 'pythonTerminalEnvVarActivation' is active
    2024-12-05 16:59:42.824 [info] Experiment 'pythonTestAdapter' is active
    2024-12-05 16:59:42.824 [info] Native locator: Refresh started
    2024-12-05 16:59:44.047 [info] > pyenv which python
    2024-12-05 16:59:44.047 [info] cwd: .
    2024-12-05 16:59:44.105 [info] > /datascope/slurm/miniconda3/bin/conda info --json
    2024-12-05 16:59:46.693 [info] Conda environment manager found at: /usr/local/miniconda3/bin/conda
    2024-12-05 16:59:46.713 [info] Conda environment manager found at: /datascope/slurm/miniconda3/bin/conda
    2024-12-05 16:59:46.718 [info] Conda environment manager found at: /datascope/slurm/aarch64/miniconda3/bin/conda
    2024-12-05 16:59:46.816 [info] Conda environment manager found at: /home/dobos/project/lsst/conda/bin/conda
    2024-12-05 16:59:46.833 [info] Native locator: Refresh finished in 4967 ms
    

    I don't know where those paths are coming from because they're not listed when I simply run /datascope/slurm/miniconda3/bin/conda info --json. I have the python.condaPath value configured to the one I want to use but vscode insists on picking up the last one in the above list which is of course incorrect because the environment I want to use is under a different conda installation. This is very annoying because I have to switch back and forth between conda installation (x64 and aarch64) as well as various environments.

  19. dobos commented on Dec 5, 2024

    @dobos

    I'd like to confirm that setting the python locator from native to js solves the issue I reported above, and the python extension finds the correct conda installation based on the selected environment, and can discover the list of unit test.

  20. oleg-korshunov commented on Dec 22, 2024

    @oleg-korshunov

    Yes, there is a solution for it. I am using wsl, so I opened settings and looked for wsl python locator option and set it to "js". Default "native" doesn't work.

    Image

    THX! spent the whole day trying to fix this pain in the ass, when I work with env from poetry everything is ok, now I needed switched to conda and this problem arose

    also used Wsl, vscode (version 1.89.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-testingbugIssue identified by VS Code Team member as probable buginfo-neededIssue requires more information from postertriage-neededNeeds assignment to the proper sub-team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions