Skip to content

Legacy discovery does not work for folders added to workspace after python extension activated #26011

@vaclavHala

Description

@vaclavHala

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:

  1. 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)
  2. 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
  1. 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:

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions