Skip to content

Launching via GitHub Desktop causes tests to fail #19090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pstjohn opened this issue May 9, 2022 · 7 comments
Closed

Launching via GitHub Desktop causes tests to fail #19090

pstjohn opened this issue May 9, 2022 · 7 comments
Assignees
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug investigating We are looking into the cause of the issue

Comments

@pstjohn
Copy link

pstjohn commented May 9, 2022

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.languageServer setting: 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>"

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label May 9, 2022
@karthiknadig karthiknadig added bug Issue identified by VS Code Team member as probable bug area-environments Features relating to handling interpreter environments labels May 9, 2022
@karrtikr
Copy link

karrtikr commented May 9, 2022

Can you try to change the setting terminal.integrated.inheritEnv to false as outlined in https://code.visualstudio.com/updates/v1_36#_launch-terminals-with-clean-environments and see if it helps?

@karrtikr karrtikr added the info-needed Issue requires more information from poster label May 9, 2022
@pstjohn
Copy link
Author

pstjohn commented May 9, 2022

Looks like that's already unchecked -- here's my settings.json:

{
    "terminal.integrated.fontFamily": "Menlo for Powerline",
    "python.linting.flake8Enabled": true,
    "python.formatting.provider": "black",
    "python.linting.flake8Path": "/Users/pstjohn/mambaforge/bin/flake8",
    "python.formatting.yapfPath": "/Users/pstjohn/mambaforge/bin/yapf",
    "git.autofetch": true,
    "git.ignoreLegacyWarning": true,
    "workbench.colorTheme": "Solarized Dark",
    "editor.fontSize": 13,
    "python.formatting.blackPath": "/Users/pstjohn/mambaforge/bin/black",
    "python.sortImports.args": [
        "--profile=black"
    ],
    "python.sortImports.path": "/Users/pstjohn/mambaforge/bin/isort",
    "[python]": {
        "editor.formatOnSaveMode": "file",
        "editor.codeActionsOnSave": {
            "source.organizeImports": true
        }
    },
    "editor.formatOnSave": true,
    "editor.rulers": [
        88
    ],
    "python.languageServer": "Pylance",
    "python.testing.autoTestDiscoverOnSaveEnabled": false,
    "editor.formatOnSaveMode": "modificationsIfAvailable",
    "python.linting.flake8Args": [
        "--max-line-length=88",
        "--extend-ignore=E203"
    ],
    "terminal.integrated.customGlyphs": false,
    "terminal.integrated.inheritEnv": false,
    "terminal.integrated.env.osx": {
        "PATH": ""
    },
    "python.terminal.activateEnvInCurrentTerminal": true
}

@karrtikr karrtikr added investigating We are looking into the cause of the issue and removed info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team labels May 9, 2022
@karrtikr
Copy link

karrtikr commented 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?

python -c"import sys;print(sys.executable)"
conda run -n graphenv --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/linter.py -p flake8 ~/mambaforge/bin/flake8 --max-line-length=88 --extend-ignore=E203 ./tests/test_tsp.py

Is VIRTUAL_ENV set in the terminal?

@karrtikr karrtikr added the info-needed Issue requires more information from poster label May 9, 2022
@pstjohn
Copy link
Author

pstjohn commented 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:

$ python -c"import sys;print(sys.executable)"
$HOME/mambaforge/envs/pytest_issue/bin/python

The conda run command seems to work as well -- it really seems limited to just pytest.

$ 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/linter.py -p flake8 ~/mambaforge/bin/flake8 --max-line-length=88 --extend-ignore=E203 ./tests/test_my_module.py 
>>>PYTHON-EXEC-OUTPUT
<<<PYTHON-EXEC-OUTPUT

VIRTUAL_ENV doesn't appear to be set:

$ echo $VIRTUAL_ENV

Screen Shot 2022-05-09 at 2 57 09 PM

@karrtikr karrtikr removed the info-needed Issue requires more information from poster label May 9, 2022
@karrtikr
Copy link

karrtikr commented May 9, 2022

Thanks for the info, it is a dup of #19070.

What happens is conda run uses 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.

@karrtikr karrtikr closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2022
@pstjohn
Copy link
Author

pstjohn commented May 10, 2022

As a workaround do not launch Github Desktop using a conda environment.

Hmm, I'm launching Github Desktop from it's Applications/ app shortcut, not via a terminal (that might have an activated conda environment).

@karrtikr
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-environments Features relating to handling interpreter environments bug Issue identified by VS Code Team member as probable bug investigating We are looking into the cause of the issue
Projects
None yet
Development

No branches or pull requests

3 participants