Type: Bug
Behaviour
I'm using pytest in the legacy mode (i.e. env extension disabled). When I'm already in vscode multi-folder workspace mode, and I add new folder to my workspace, test integration in the new folder does not work and I have to restart vscode to fix this. In the Python Output window I can see message
[error] Unable to find test adapter for workspace.
Investigation and proposed solution
I believe this happens because the method activateLegacyWorkspace is only ever called from activate, meaning if new workspace folder is added after the activation, it does not get initialized so that the this.testAdapters map will never contain entry for the added workspace folder.
|
this.activateLegacyWorkspace(workspace); |
Solution is probably to listen for workspace folder changes and run the activate method for newly added folders.
Similar problem may exist for the new project mode, I'm not yet familiar with how that works so haven't tested that.
Steps to reproduce:
- be in multifolder mode, the easiest is to just
File > Add Folder to Workspace (this step is important, if you start from single folder mode, adding another folder will restart Extension Host in new mode which will re-activate whole python extension and the bug will not manifest)
- add new folder to the workspace that contains the following files:
// .vscode/settings.json
{
"python.useEnvironmentsExtension": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": ["tests"]
}
// tests/test_foo.py
def test_foo():
pass
- run
Refresh tests action from the testing panel
expected
new entry for the new folder containing test_foo appears in the panel
actual
test does not appear, Python output contains error
[error] Unable to find test adapter for workspace.
Extension version: 2026.4.0
VS Code version: Code 1.100.2 (848b80aeb52026648a8ff9f7c45a9b0a80641e2e, 2025-05-14T21:47:40.416Z)
OS version: Linux x64 6.1.0-18-amd64
Modes:
Type: Bug
Behaviour
I'm using pytest in the legacy mode (i.e. env extension disabled). When I'm already in vscode multi-folder workspace mode, and I add new folder to my workspace, test integration in the new folder does not work and I have to restart vscode to fix this. In the Python Output window I can see message
Investigation and proposed solution
I believe this happens because the method
activateLegacyWorkspaceis only ever called fromactivate, meaning if new workspace folder is added after the activation, it does not get initialized so that thethis.testAdaptersmap will never contain entry for the added workspace folder.vscode-python/src/client/testing/testController/controller.ts
Line 241 in af97557
Solution is probably to listen for workspace folder changes and run the activate method for newly added folders.
Similar problem may exist for the new project mode, I'm not yet familiar with how that works so haven't tested that.
Steps to reproduce:
File > Add Folder to Workspace(this step is important, if you start from single folder mode, adding another folder will restart Extension Host in new mode which will re-activate whole python extension and the bug will not manifest)Refresh testsaction from the testing panelexpected
new entry for the new folder containing
test_fooappears in the panelactual
test does not appear, Python output contains error
Extension version: 2026.4.0
VS Code version: Code 1.100.2 (848b80aeb52026648a8ff9f7c45a9b0a80641e2e, 2025-05-14T21:47:40.416Z)
OS version: Linux x64 6.1.0-18-amd64
Modes: