Title: Starting with v2026.2.0 `unittest` test discovery does not work for custom `--start-directory` (aka `-s`) in `python.testing.unittestArgs` · Issue #26033 · microsoft/vscode-python · GitHub
Open Graph Title: Starting with v2026.2.0 `unittest` test discovery does not work for custom `--start-directory` (aka `-s`) in `python.testing.unittestArgs` · Issue #26033 · microsoft/vscode-python
X Title: Starting with v2026.2.0 `unittest` test discovery does not work for custom `--start-directory` (aka `-s`) in `python.testing.unittestArgs` · Issue #26033 · microsoft/vscode-python
Description: Type: Bug Behaviour In a project using unittest and relying on custom --start-directory (see .vscode/settings.json below) test discovery fails with ImportError: Start directory is not importable: '/workspaces/project/subdir'. { "python.t...
Open Graph Description: Type: Bug Behaviour In a project using unittest and relying on custom --start-directory (see .vscode/settings.json below) test discovery fails with ImportError: Start directory is not importable: '...
X Description: Type: Bug Behaviour In a project using unittest and relying on custom --start-directory (see .vscode/settings.json below) test discovery fails with ImportError: Start directory is not importable: &...
Opengraph URL: https://github.com/microsoft/vscode-python/issues/26033
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Starting with v2026.2.0 `unittest` test discovery does not work for custom `--start-directory` (aka `-s`) in `python.testing.unittestArgs`","articleBody":"Type: \u003cb>Bug\u003c/b>\n\n# Behaviour\n\nIn a project using `unittest` and relying on custom `--start-directory` (see `.vscode/settings.json` below) test discovery fails with `ImportError: Start directory is not importable: '/workspaces/project/subdir'`.\n```json\n{\n \"python.testing.pytestEnabled\": false,\n \"python.testing.unittestArgs\": [\n \"--start-directory\",\n \"subdir/\"\n ],\n \"python.testing.unittestEnabled\": true\n}\n```\n\nExpected behaviour should be consistent with running\n```sh\npython3 -m unittest discover --start-directory subdir/\n```\n\n## Steps to reproduce:\n\n1. Open workspace\n2. Navigate to _Testing_ tab on the left\n3. Try to discover tests\n4. Observe _Unittest Discovery Error_\n\nI've tried different versions of the extension and the issue was introduced [between v2026.0.0 and v2026.2.0](https://github.com/microsoft/vscode-python/compare/v2026.0.0...v2026.2.0), most likely by #25780. After this change the extension seems to unconditionally override `--top-level-directory` (aka `-t`) from `python.testing.unittestArgs` with workspace root via `PROJECT_ROOT_PATH` environment variable:\nhttps://github.com/microsoft/vscode-python/blob/ef1b46997fc30355d220e9e12046927d3fdafdd5/python_files/unittestadapter/discovery.py#L144-L149\nIf the directory to start discovery is not importable from workspace root (the new top level directory) this becomes an issue.\nSee [`unittest` docs](https://docs.python.org/3/library/unittest.html#test-discovery):\n> In order to be compatible with test discovery, all of the test files must be [modules](https://docs.python.org/3/tutorial/modules.html#tut-modules) or [packages](https://docs.python.org/3/tutorial/modules.html#tut-packages) importable from the top-level directory of the project...\n\nI've also noticed that existing extension's unit tests cover only the trivial case of `\"python.testing.unittestArgs\": [\"-s\", \".\"]`. That's probably why the issue with `[\"-s\", \"something/else/\"]` went unnoticed.\n\n\u003c!--\n**After** creating the issue on GitHub, you can add screenshots and GIFs of what is happening. Consider tools like https://www.cockos.com/licecap/, https://github.com/phw/peek or https://www.screentogif.com/ for GIF creation.\n-->\n\n\u003c!-- **NOTE**: Please do provide logs from Python Output panel. -->\n# Diagnostic data\n\nData below is from a project using Linux devcontainer, but the issue is reproducible on macOS host as well. And in a different project too. So I wouldn't pay too much attention to the specific of the environment listed below.\n\u003cdetails>\n\n\u003csummary>Output for \u003ccode>Python\u003c/code> in the \u003ccode>Output\u003c/code> panel (\u003ccode>View\u003c/code>→\u003ccode>Output\u003c/code>, change the drop-down the upper-right of the \u003ccode>Output\u003c/code> panel to \u003ccode>Python\u003c/code>)\n\u003c/summary>\n\n\u003cp>\n\n```\n2026-07-09 21:24:59.207 [info] Experiment 'pythonSurveyNotificationcf' is active\n2026-07-09 21:24:59.207 [info] Environment discovery is managed by the Python Environments extension (ms-python.vscode-python-envs). Check the \"Python Environments\" output channel for environment-specific logs.\n2026-07-09 21:24:59.389 [info] [test-by-project] Activating project-based testing mode\n2026-07-09 21:24:59.389 [info] [test-by-project] Discovering projects for workspace: /workspaces/project\n2026-07-09 21:24:59.389 [info] [test-by-project] Found 1 total Python projects from API\n2026-07-09 21:24:59.389 [info] [test-by-project] Filtered to 1 projects in workspace\n2026-07-09 21:24:59.389 [info] [test-by-project] Creating adapter for: project at file:///workspaces/project\n2026-07-09 21:24:59.498 [info] > pyenv which python\n2026-07-09 21:24:59.498 [info] cwd: .\n2026-07-09 21:24:59.582 [info] [test-by-project] Registered 1 project(s) for /workspaces/project\n2026-07-09 21:24:59.582 [info] [test-by-project] Activated 1 project(s) for /workspaces/project\n2026-07-09 21:24:59.582 [info] [test-by-project] Subscribed to Python project changes\n2026-07-09 21:24:59.583 [info] Active interpreter [/workspaces/project]: /usr/local/bin/python\n2026-07-09 21:25:00.987 [info] Starting Pylance language server.\n2026-07-09 21:25:22.236 [info] [test-by-project] Cleaned up 0 test items for workspace: /workspaces/project\n2026-07-09 21:25:22.236 [info] [test-by-project] Discovering projects for workspace: /workspaces/project\n2026-07-09 21:25:22.236 [info] [test-by-project] Found 1 total Python projects from API\n2026-07-09 21:25:22.236 [info] [test-by-project] Filtered to 1 projects in workspace\n2026-07-09 21:25:22.236 [info] [test-by-project] Creating adapter for: project at file:///workspaces/project\n2026-07-09 21:25:22.236 [info] [test-by-project] Registered 1 project(s) for /workspaces/project\n2026-07-09 21:25:22.245 [info] [test-by-project] Starting discovery for 1 project(s) in workspace\n2026-07-09 21:25:22.245 [info] [test-by-project] Discovering tests for project: project (Python 3.13)\n2026-07-09 21:25:22.248 [info] Environment variables set for unittest discovery: TEST_RUN_PIPE=/tmp/python-test-discovery-2eb38c8fc0f5a9af5368\n2026-07-09 21:25:22.248 [info] [test-by-project] Setting PROJECT_ROOT_PATH=/workspaces/project for unittest discovery\n2026-07-09 21:25:22.248 [info] Using environment extension for unittest discovery in workspace /workspaces/project\n2026-07-09 21:25:22.252 [info] Started unittest discovery subprocess (environment extension) for workspace /workspaces/project\n2026-07-09 21:25:22.323 [info] PROJECT_ROOT_PATH is set, using /workspaces/project as top_level_dir for discovery\n\n2026-07-09 21:25:22.325 [error] Unittest test discovery error for workspace: /workspaces/project \n Traceback (most recent call last):\n File \"/home/vscode/.vscode-server/extensions/ms-python.python-2026.4.0-linux-arm64/python_files/unittestadapter/discovery.py\", line 80, in discover_tests\n suite = loader.discover(start_dir, pattern, top_level_dir)\n File \"/usr/local/lib/python3.13/unittest/loader.py\", line 308, in discover\n raise ImportError('Start directory is not importable: %r' % start_dir)\nImportError: Start directory is not importable: '/workspaces/project/subdir'\n\n2026-07-09 21:25:22.325 [warning] --- [test-by-project] Import error during unittest discovery for project at /workspaces/project. This may be caused by test files in nested project directories that require different dependencies. If these tests are discovered successfully by their own project (with the correct Python environment), this error can be safely ignored. To avoid this, consider excluding nested project paths from parent project discovery. ---\n2026-07-09 21:25:22.325 [error] Test Discovery named pipe /tmp/python-test-discovery-2eb38c8fc0f5a9af5368 error: [TypeError: Cannot read properties of null (reading 'path')\n\tat e (/home/vscode/.vscode-server/extensions/ms-python.python-2026.4.0-linux-arm64/out/client/extension.js:2:991831)\n\tat t.TestDiscoveryHandler.processDiscovery (/home/vscode/.vscode-server/extensions/ms-python.python-2026.4.0-linux-arm64/out/client/extension.js:2:968443)\n\tat u.resolveDiscovery (/home/vscode/.vscode-server/extensions/ms-python.python-2026.4.0-linux-arm64/out/client/extension.js:2:965238)\n\tat /home/vscode/.vscode-server/extensions/ms-python.python-2026.4.0-linux-arm64/out/client/extension.js:2:958373\n\tat b.callback (/home/vscode/.vscode-server/extensions/ms-python.python-2026.4.0-linux-arm64/out/client/extension.js:2:991030)\n\tat Object.thunk (/home/vscode/.vscode-server/extensions/ms-python.python-2026.4.0-linux-arm64/out/client/extension.js:2:2064800)]\n2026-07-09 21:25:22.330 [info] Unittest discovery completed for workspace /workspaces/project\n2026-07-09 21:25:22.330 [info] [test-by-project] Project project (Python 3.13) discovery completed\n2026-07-09 21:25:22.330 [info] [test-by-project] Discovery complete: 1/1 projects completed\n```\n\n\u003c/p>\n\u003c/details>\n\n\nExtension version: 2026.4.0\nVS Code version: Code 1.127.0 (4fe60c8b1cdac1c4c174f2fb180d0d758272d713, 2026-06-30T10:52:33+02:00)\nOS version: Darwin arm64 25.5.0\nModes:\nRemote OS version: Linux arm64 6.12.76-linuxkit\n\n- Python version (& distribution if applicable, e.g. Anaconda): 3.13.14.final.0\n- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): System\n- Value of the `python.languageServer` setting: Default\n\n\u003cdetails>\n\u003csummary>User Settings\u003c/summary>\n\u003cp>\n\n```\n\nlanguageServer: \"Pylance\"\n\ntesting\n• unittestArgs: \"\u003cplaceholder>\"\n• unittestEnabled: true\n\n```\n\u003c/p>\n\u003c/details>\n\n\u003cdetails>\n\u003csummary>Installed Extensions\u003c/summary>\n\n|Extension Name|Extension Id|Version|\n|---|---|---|\n|autopep8|ms-|2026.4.0|\n|copilot-chat|Git|0.55.0|\n|debugpy|ms-|2026.6.0|\n|js-debug|ms-|1.117.0|\n|jsts-chat-features|Typ|0.0.4|\n|python|ms-|2026.4.0|\n|ruff|cha|2026.56.0|\n|vscode-eslint|dba|3.0.24|\n|vscode-js-profile-table|ms-|1.0.10|\n|vscode-pylance|ms-|2026.2.1|\n|vscode-python-envs|ms-|1.36.0|\n\u003c/details>\n\u003cdetails>\n\u003csummary>System Info\u003c/summary>\n\n|Item|Value|\n|---|---|\n|CPUs|Apple M4 Max (14 x 2400)|\n|GPU Status|2d_canvas: enabled\u003cbr>GPU0: VENDOR= 0x106b [Google Inc. (Apple)], DEVICE=0x0000 [ANGLE (Apple, ANGLE Metal Renderer: Apple M4 Max, Version 26.5.2 (Build 25F84))], DRIVER_VENDOR=Apple, DRIVER_VERSION=26.5.2 *ACTIVE*\u003cbr>Machine model name: Mac\u003cbr>Machine model version: 16.6\u003cbr>direct_rendering_display_compositor: disabled_off_ok\u003cbr>gpu_compositing: enabled\u003cbr>multiple_raster_threads: enabled_on\u003cbr>opengl: enabled_on\u003cbr>rasterization: enabled\u003cbr>raw_draw: disabled_off_ok\u003cbr>skia_graphite: enabled_on\u003cbr>trees_in_viz: disabled_off\u003cbr>video_decode: enabled\u003cbr>video_encode: enabled\u003cbr>webgl: enabled\u003cbr>webgpu: enabled\u003cbr>webnn: disabled_off|\n|Load (avg)|3, 3, 2|\n|Memory (System)|36.00GB (0.28GB free)|\n|Process Argv|. --crash-reporter-id 684fb168-0444-4033-bb04-7818c72bdb86|\n|Screen Reader|no|\n|VM|0%|\n\n|Item|Value|\n|---|---|\n|Remote|Dev Container @ desktop-linux|\n|OS|Linux arm64 6.12.76-linuxkit|\n|CPUs|unknown (14 x 0)|\n|Memory (System)|31.29GB (28.55GB free)|\n|VM|0%|\n\u003c/details>\u003cdetails>\n\u003csummary>A/B Experiments\u003c/summary>\n\n```\nvsliv368cf:30146710\npythonvspyt551cf:31249601\nbinariesv615:30325510\nnativeloc1:31344060\ndwcopilot:31170013\ndwoutputs:31242946\ncopilot_t_ci:31333650\ne5gg6876:31282496\npythonrdcb7:31342333\n6518g693:31463988\naj953862:31281341\n6abeh943:31336334\nenvsactivate1:31538736\neditstats-enabled:31346257\ncloudbuttont:31379625\n3efgi100_wstrepl:31403338\n839jf696:31457053\nec5jj548:31422691\ncp_cls_t_966_ss:31526232\n8hhj4413:31478653\nge8j1254_inline_auto_hint_haiku:31490510\n38bie571_auto:31478677\ncp_cls_c_1081:31454833\nconptydll_true:31498968\nia-use-proxy-models-svc:31452481\ne9c30283:31461165\ntest_control1:31471004\n46204921:31447328\ncapi_axe_098a3278:31544981\nidci7584:31464702\ne3e4d672:31494082\nei9d7968:31496641\nnes-extended-on:31455476\nchat:31457767\n8hig5102:31480529\nah:31461780\n89g7j272:31518289\n7e187181:31503455\ni2gc6536:31499202\n52612955:31516516\nghj88844:31499326\nddid_c:31478207\nhmra_i5g22:31518061\nie3bb177:31543534\n7df3h592:31512476\ncp_cls_t_1082:31535311\nlogging_enabled_new:31498466\ndb5d2638:31499441\njb_cp_cls_t_632:31543129\n748c7209:31512887\n32d76977:31512328\nha629193:31508444\ncdk-lw-on:31524445\nf9bf7985:31543584\na1ije391_t:31540920\nhgf2d445:31529595\n41836166:31537719\nprpt_srch:31518468\njbcp_cls_pctr_t:31531130\n61138546:31518536\ncp_intellij_t_nes:31533504\ngf14b233:31526830\nnes-curr-leftover-1500:31538366\nh561g132:31533256\nsession_8:31532895\nihg5j128:31534457\njh7i3328:31546038\n7g2b5551:31542111\nsandbox-ui-on-2:31543161\nnes-nc-nf-2k:31546582\n\n```\n\n\u003c/details>\n\n\u003c!-- generated by issue reporter --","author":{"url":"https://github.com/i-ky","@type":"Person","name":"i-ky"},"datePublished":"2026-07-09T22:30:43Z","url":"https://github.com/microsoft/vscode-python/issues/26033"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:39becbb8-bcef-f7f2-cbfc-a441a1cce2a8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CAEC:19B7CA:1F5E88:2DBD21:6AFD78BE |
| html-safe-nonce | efd5e54ea4c94e7452929cd835cbeb41fb868fbeb4acce2486fa9c5ec5e44799 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQUVDOjE5QjdDQToxRjVFODg6MkRCRDIxOjZBRkQ3OEJFIiwidmlzaXRvcl9pZCI6IjUzNTY0MjM0ODgxMDM4NzI3MDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f0278018ac46872bd7880fd08ab7a0d030f79df43603bb16fbf3e147bf15e809 |
| hovercard-subject-tag | issue:4850377776 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/vscode-python/26033/issue_layout |
| twitter:image | https://opengraph.githubassets.com/42000e25d70cf3a20c109ac7b5e52b9977c869e92959c09365acb8c6c9c00f2a/microsoft/vscode-python/issues/26033 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/42000e25d70cf3a20c109ac7b5e52b9977c869e92959c09365acb8c6c9c00f2a/microsoft/vscode-python/issues/26033 |
| og:image:alt | Type: Bug Behaviour In a project using unittest and relying on custom --start-directory (see .vscode/settings.json below) test discovery fails with ImportError: Start directory is not importable: '... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | i-ky |
| hostname | github.com |
| expected-hostname | github.com |
| None | 544ff6b59bd215c4609120f6e334dbd0b00d34fb6f8bc03a476f72256998887e |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/vscode-python git https://github.com/microsoft/vscode-python.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 106462765 |
| octolytics-dimension-repository_nwo | microsoft/vscode-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | true |
| octolytics-dimension-repository_parent_id | 49946255 |
| octolytics-dimension-repository_parent_nwo | DonJayamanne/pythonVSCode |
| octolytics-dimension-repository_network_root_id | 49946255 |
| octolytics-dimension-repository_network_root_nwo | DonJayamanne/pythonVSCode |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 71c92f8b27ec5e9aa6f6477b4e067a4727fc9edb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width