Skip to content
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

ImportError: Error importing plugin "vscode_pytest": No module named 'vscode_pytest' #24414

Closed
talebia opened this issue Nov 11, 2024 · 10 comments
Assignees
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team

Comments

@talebia
Copy link

talebia commented Nov 11, 2024

similar to 23192 I'm using python 3.10.10 and below are the logs:

2024-11-11 12:17:09.161 [debug] Testing: Manually triggered test refresh
2024-11-11 12:17:09.161 [debug] Testing: Clearing all discovered tests
2024-11-11 12:17:09.161 [debug] Testing: Forcing test data refresh
2024-11-11 12:17:09.161 [debug] Testing: Refreshing all test data
2024-11-11 12:17:09.161 [debug] Found cached env for C:\Python\python.exe
2024-11-11 12:17:09.162 [info] Discover tests for workspace name: compute.rhino3d - uri: c:\dev\MyProject\MySolution
2024-11-11 12:17:09.162 [info] Running discovery for pytest using the new test adapter.
2024-11-11 12:17:09.162 [debug] Found cached env for C:\Python\python.exe
2024-11-11 12:17:09.163 [debug] Starting Test Discovery named pipe
2024-11-11 12:17:09.163 [debug] Creating named pipe server on \\.\pipe\python-test-discovery-a96448a0ff04d34aa1ac-sock
2024-11-11 12:17:09.165 [warning] The cwd resolves to a different path, checking if it has a symbolic link somewhere in its path.
2024-11-11 12:17:09.166 [info] All environment variables set for pytest discovery: {"ALLUSERSPROFILE":"C:\\ProgramData","APPDATA":"C:\\Users\\USER.NAME\\AppData\\Roaming","TEST_RUN_PIPE":"\\\\.\\pipe\\python-test-discovery-a96448a0ff04d34aa1ac-sock"}
2024-11-11 12:17:09.166 [debug] could not find a pixi interpreter for the interpreter at C:\Python\python.exe
2024-11-11 12:17:09.207 [debug] Activation Commands received undefined for shell cmd, resource c:\dev\MyProject\MySolution and interpreter C:\Python\python.exe
2024-11-11 12:17:09.219 [debug] Running pytest discovery with command: -m pytest -p vscode_pytest --collect-only myco_tests/bdd_tests for workspace c:\dev\MyProject\MySolution.
2024-11-11 12:17:09.219 [info] > C:\Python\python.exe -m pytest -p vscode_pytest --collect-only myco_tests/bdd_tests
2024-11-11 12:17:09.219 [info] cwd: .
2024-11-11 12:17:09.746 [error] Traceback (most recent call last):
  File "C:\Python\lib\site-packages\_pytest\config\__init__.py", line 864, in import_plugin
    __import__(importspec)
ModuleNotFoundError: No module named 'vscode_pytest'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "runpy.py", line 196, in _run_module_as_main
  File "runpy.py", line 86, in _run_code
  File "C:\Python\lib\site-packages\pytest\__main__.py", line 7, in <module>
    raise SystemExit(pytest.console_main())
  File "C:\Python\lib\site-packages\_pytest\config\__init__.py", line 206, in console_main
    code = main()
  File "C:\Python\lib\site-packages\_pytest\config\__init__.py", line 159, in main
    config = _prepareconfig(args, plugins)
  File "C:\Python\lib\site-packages\_pytest\config\__init__.py", line 346, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "C:\Python\lib\site-packages\pluggy\_hooks.py", line 513, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
  File "C:\Python\lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "C:\Python\lib\site-packages\pluggy\_callers.py", line 139, in _multicall
    raise exception.with_traceback(exception.__traceback__)
  File "C:\Python\lib\site-packages\pluggy\_callers.py", line 122, in _multicall
    teardown.throw(exception)  # type: ignore[union-attr]
  File "C:\Python\lib\site-packages\_pytest\helpconfig.py", line 106, in pytest_cmdline_parse
    config = yield
  File "C:\Python\lib\site-packages\pluggy\_callers.py", line 103, in _multicall
    res = hook_impl.function(*args)
  File "C:\Python\lib\site-packages\_pytest\config\__init__.py", line 1151, in pytest_cmdline_parse
    self.parse(args)
  File "C:\Python\lib\site-packages\_pytest\config\__init__.py", line 1500, in parse
    self._preparse(args, addopts=addopts)
  File "C:\Python\lib\site-packages\_pytest\config\__init__.py", line 1383, in _preparse
    self.pluginmanager.consider_preparse(args, exclude_only=False)
  File "C:\Python\lib\site-packages\_pytest\config\__init__.py", line 794, in consider_preparse
    self.consider_pluginarg(parg)
  File "C:\Python\lib\site-packages\_pytest\config\__init__.py", line 817, in consider_pluginarg
    self.import_plugin(arg, consider_entry_points=True)
  File "C:\Python\lib\site-packages\_pytest\config\__init__.py", line 866, in import_plugin
    raise ImportError(
  File "C:\Python\lib\site-packages\_pytest\config\__init__.py", line 864, in import_plugin
    __import__(importspec)
ImportError: Error importing plugin "vscode_pytest": No module named 'vscode_pytest'

2024-11-11 12:17:09.769 [error] Subprocess exited unsuccessfully with exit code 1 and signal null on workspace c:\dev\MyProject\MySolution.
2024-11-11 12:17:09.769 [error] Subprocess exited unsuccessfully with exit code 1 and signal null on workspace c:\dev\MyProject\MySolution. Creating and sending error discovery payload
2024-11-11 12:17:09.769 [error] pytest test discovery error for workspace:  c:\dev\MyProject\MySolution 
  
 The python test process was terminated before it could exit on its own, the process errored with: Code: 1, Signal: null for workspace c:\dev\MyProject\MySolution
2024-11-11 12:25:13.769 [debug] Found cached env for C:\Python\python.exe
2024-11-11 12:25:13.769 [debug] Found cached env for C:\Python\python.exe
2024-11-11 12:29:49.793 [debug] Found cached env for C:\Python\python.exe
2024-11-11 12:29:54.937 [debug] Received shell integration sequence for powershell
2024-11-11 12:30:00.154 [debug] Found cached env for C:\Python\python.exe
2024-11-11 12:30:00.154 [debug] Selected python for [c:\dev\MyProject\MySolution] is [global] type: C:\Python\python.exe
2024-11-11 12:30:00.178 [debug] Extension unknown accessed getActiveEnvironmentPath with args: undefined
2024-11-11 12:30:00.178 [debug] Extension unknown accessed resolveEnvironment with args: {"id":"C:\\PYTHON\\PYTHON.EXE","path":"C:\\Python\\python.exe"}
2024-11-11 12:30:05.043 [debug] Received shell integration sequence for powershell
2024-11-11 12:30:11.862 [debug] Found cached env for C:\Python\python.exe
2024-11-11 12:30:11.863 [debug] Selected python for [c:\dev\MyProject\MySolution] is [global] type: C:\Python\python.exe
2024-11-11 12:30:11.893 [debug] Extension unknown accessed resolveEnvironment with args: {"id":"C:\\PYTHON\\PYTHON.EXE","path":"C:\\Python\\python.exe"}
2024-11-11 12:30:11.893 [debug] Extension unknown accessed getActiveEnvironmentPath with args: undefined
2024-11-11 12:30:11.919 [debug] Received shell integration sequence for powershell
2024-11-11 12:31:14.693 [debug] Found cached env for C:\Python\python.exe

Similarly can get around it by using something like this but not sustainable.

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Nov 11, 2024
@karthiknadig
Copy link
Member

@talebia Can you check if the vscode_pytest exists in the extensions directory? You can find the extensions directory by running this command:
Image

Then open the folder that starts with ms-python.python. In that directory there should be python_files directory, open it. There you should find vscode_pytest:
Image

Image

Image

Make sure that this folder exists. If it does not exit, try uninstalling python extension, close all vscode instances, and reopen vs code and install python extension again.

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Nov 11, 2024
@talebia
Copy link
Author

talebia commented Nov 11, 2024

@karthiknadig I do seem to have it although slightly different version that above: Image

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Nov 11, 2024
@karthiknadig
Copy link
Member

That looks correct. In the logs you pasted, it looks like the environment variables were truncated, can you make sure it has PYTHONPATH set to:
Image

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Nov 11, 2024
@talebia
Copy link
Author

talebia commented Nov 11, 2024

I can set the env var and it works fine. though would I have to update it manually each time there's a new version? plus I'm not sure why it was not set in the first place..

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Nov 11, 2024
@karthiknadig
Copy link
Member

@talebia You should not have to set this, it should set automatically. It looked like in the logs only TEST_RUN_PIPE got set, the PYTHONPATH did not. This might be a bug.

@eleanorjboyd
Copy link
Member

Thanks for all the info above, very weird the env vars are not getting set correctly. @talebia could you describe your setup? ie are you on a remote machine, what type of machine you have, where is this folder you are running test discovery on located. I am seeing in your logs 2024-11-11 12:17:09.165 [warning] The cwd resolves to a different path, checking if it has a symbolic link somewhere in its path. which means the realpath of the cwd is not the cwd (it evaluates to something else) but it does not find a symlink in the cwd so I am trying to think what scenario it might be and if thats related

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Nov 11, 2024
@eleanorjboyd
Copy link
Member

One thing to try that just came to mind- could you disable pytest and enable unittest instead and trying running discovery that way? To do so update your settings.json for your workspace:

    "python.testing.unittestArgs": ["-v", "-s", ".", "-p", "*test*.py"],
    "python.testing.pytestEnabled": false,
    "python.testing.unittestEnabled": true

now RELOAD the VS Code window (important step to make sure the setting gets updated correctly)

then attempt to discover a unittest, which you can use this example if you don't have one.

import unittest


class TestExample(unittest.TestCase):
    def test_true_unittest(self):
        assert True

see how that goes as unittest uses the same env var substitution but with some small changes

Copy link

Because we have not heard back with the information we requested, we are closing this issue for now. If you are able to provide the info later on, then we will be happy to re-open this issue to pick up where we left off.

Happy Coding!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Dec 11, 2024
@joetristano
Copy link

I'm having a similar issue with a portable embedded install. I'm using this https://github.com/jtmoon79/PythonEmbed4Win to leverage standalone Python execution with an embedded installer. I've set my Python path but vscode can't find the plugin.

@eleanorjboyd
Copy link
Member

Hi @joetristano! How have you set your path? We made some changes to append to the path when you click to start a test run but given the changes you have made is the extension able to edit the path to include this addition?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

4 participants