Repository navigation
Closed as not planned
Labels
area-environmentsFeatures relating to handling interpreter environmentsFeatures relating to handling interpreter environmentsbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable buginvestigatingWe are looking into the cause of the issueWe are looking into the cause of the issue
Description
Related to #18431
I was able to track down steps to reproduce my issue. On a Mac, using GitHub Desktop Version 3.0.0 with vscode as my default editor. Using a basic repo here, which just uses a conda environment to run a some pytest tests: https://github.com/pstjohn/vscode-pytest-demo
If I open the repo using the github desktop "open in external editor" command, pytests fail with the following error, indicating that the editor is picking up the system's python 2.7; not my local conda environment.
If I manually open the repository (in this case using code . from the repository's directory in iTerm2), the tests are able to be discovered and run fine.
conda run -n pytest_issue --no-capture-output python ~/.vscode/extensions/ms-python.python-2022.6.0/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.6.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir . -s --cache-clear tests
cwd: .
[ERROR 2022-4-9 14:53:28.667]: Error discovering pytest tests:
[n [Error]: Traceback (most recent call last):
File "/Users/pstjohn/.vscode/extensions/ms-python.python-2022.6.0/pythonFiles/get_output_via_markers.py", line 26, in <module>
runpy.run_path(module, run_name="__main__")
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 252, in run_path
return _run_module_code(code, init_globals, run_name, path_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/Users/pstjohn/.vscode/extensions/ms-python.python-2022.6.0/pythonFiles/testing_tools/run_adapter.py", line 17, in <module>
from testing_tools.adapter.__main__ import parse_args, main
File "/Users/pstjohn/.vscode/extensions/ms-python.python-2022.6.0/pythonFiles/testing_tools/adapter/__main__.py", line 9, in <module>
from . import pytest, report
File "/Users/pstjohn/.vscode/extensions/ms-python.python-2022.6.0/pythonFiles/testing_tools/adapter/pytest/__init__.py", line 7, in <module>
from ._discovery import discover
File "/Users/pstjohn/.vscode/extensions/ms-python.python-2022.6.0/pythonFiles/testing_tools/adapter/pytest/_discovery.py", line 8, in <module>
import pytest
ImportError: No module named pytest
ERROR conda.cli.main_run:execute(41): `conda run python /Users/pstjohn/.vscode/extensions/ms-python.python-2022.6.0/pythonFiles/get_output_via_markers.py /Users/pstjohn/.vscode/extensions/ms-python.python-2022.6.0/pythonFiles/testing_tools/run_adapter.py discover pytest -- --rootdir /Users/pstjohn/Packages/vscode_pytest -s --cache-clear tests` failed. (See above for error)
at ChildProcess.<anonymous> (/Users/pstjohn/.vscode/extensions/ms-python.python-2022.6.0/out/client/extension.js:2:227541)
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)]
Diagnostic data
- Python version (& distribution if applicable, e.g. Anaconda): 3.9.10
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
- Value of the
python.languageServersetting: Pylance
User Settings
defaultLS: {"defaultLSType":"Pylance"}
envFile: "<placeholder>"
venvPath: "<placeholder>"
venvFolders: "<placeholder>"
condaPath: "<placeholder>"
pipenvPath: "<placeholder>"
poetryPath: "<placeholder>"
languageServer: "Pylance"
linting
• enabled: true
• cwd: "<placeholder>"
• Flake8Args: "<placeholder>"
• flake8Enabled: true
• flake8Path: "<placeholder>"
• lintOnSave: true
• banditArgs: "<placeholder>"
• banditEnabled: false
• banditPath: "<placeholder>"
• mypyArgs: "<placeholder>"
• mypyEnabled: false
• mypyPath: "<placeholder>"
• pycodestyleArgs: "<placeholder>"
• pycodestyleEnabled: false
• pycodestylePath: "<placeholder>"
• prospectorArgs: "<placeholder>"
• prospectorEnabled: false
• prospectorPath: "<placeholder>"
• pydocstyleArgs: "<placeholder>"
• pydocstyleEnabled: false
• pydocstylePath: "<placeholder>"
• pylamaArgs: "<placeholder>"
• pylamaEnabled: false
• pylamaPath: "<placeholder>"
• pylintArgs: "<placeholder>"
• pylintPath: "<placeholder>"
sortImports
• args: "<placeholder>"
• path: "<placeholder>"
formatting
• autopep8Args: "<placeholder>"
• autopep8Path: "<placeholder>"
• provider: "black"
• blackArgs: "<placeholder>"
• blackPath: "<placeholder>"
• yapfArgs: "<placeholder>"
• yapfPath: "<placeholder>"
testing
• cwd: "<placeholder>"
• debugPort: 3000
• nosetestArgs: "<placeholder>"
• nosetestsEnabled: undefined
• nosetestPath: "<placeholder>"
• promptToConfigure: true
• pytestArgs: "<placeholder>"
• pytestEnabled: true
• pytestPath: "<placeholder>"
• unittestArgs: "<placeholder>"
• unittestEnabled: false
• autoTestDiscoverOnSaveEnabled: false
terminal
• activateEnvironment: true
• executeInFileDir: "<placeholder>"
• launchArgs: "<placeholder>"
experiments
• enabled: true
• optInto: []
• optOutFrom: []
tensorBoard
• logDirectory: "<placeholder>"
Metadata
Metadata
Assignees
Labels
area-environmentsFeatures relating to handling interpreter environmentsFeatures relating to handling interpreter environmentsbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable buginvestigatingWe are looking into the cause of the issueWe are looking into the cause of the issue
Activity
karrtikr commentedon May 9, 2022
Can you try to change the setting
terminal.integrated.inheritEnvtofalseas outlined in https://code.visualstudio.com/updates/v1_36#_launch-terminals-with-clean-environments and see if it helps?pstjohn commentedon May 9, 2022
Looks like that's already unchecked -- here's my settings.json:
karrtikr commentedon May 9, 2022
I suspect VSCode is launched via an activated conda environment when using Github Desktop, in that case this is a dup of #19070 and is caused due to conda conda/conda#11305, conda/conda#11174.
What happens if you run the following command in VSCode terminal?
Is
VIRTUAL_ENVset in the terminal?pstjohn commentedon May 9, 2022
whoops, I pasted the pytest failure for my larger repo -- I changed it above to reflect the small demo repo I created as a minimal example, and translated your commands here to that repo as well.
Launching via github desktop with the tests failing --
The conda environment seems to be activated correctly:
The
conda runcommand seems to work as well -- it really seems limited to just pytest.VIRTUAL_ENVdoesn't appear to be set:karrtikr commentedon May 9, 2022
Thanks for the info, it is a dup of #19070.
What happens is
conda runuses the system python instead of environment python (conda/conda#11174), when the conda environment is already activated: conda/conda#11305. As a workaround do not launch Github Desktop using a conda environment.pstjohn commentedon May 10, 2022
Hmm, I'm launching Github Desktop from it's Applications/ app shortcut, not via a terminal (that might have an activated conda environment).
karrtikr commentedon May 10, 2022
I see, but for some reason it has conda environment has its default python, maybe it uses the selected interpreter for launching VSCode and you've the conda env selected? Try changing your selected interpreter.