Repository navigation
pytest test discovery does not run #25748
Copy link
Copy link
Closed as not planned
Labels
area-testingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugconfirmation pendingThe issue needs to be confirmed through a maintainer reproducing the bug.The issue needs to be confirmed through a maintainer reproducing the bug.info-neededIssue requires more information from posterIssue requires more information from poster
Description
Type: Bug
Summary
Pytest gutter icons (play buttons) are missing after VS Code starts. Test discovery does not run automatically even though python.testing.pytestEnabled is true.
Workaround: Running Test: Refresh Tests from Command Palette fixes the issue until VS Code restarts.
Steps to Reproduce
- Open a Python project with pytest configured
- Ensure
.vscode/settings.jsonhas:{ "python.testing.pytestArgs": ["tests"], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true } - Close and restart VS Code
- Open a test file (e.g.,
test_stock.py) - Expected: Green play button icons appear next to test functions
- Actual: No gutter icons, Test Explorer is empty
Workaround
Run Test: Refresh Tests from Command Palette → Icons appear and tests work.
Note: Developer: Reload Window does NOT fix the issue.
Environment
- VS Code: 1.108.2
- OS: macOS arm64 (Darwin 25.2.0)
- Python: 3.14.0
- pytest: 9.0.2
- ms-python.python: 2026.0.0
Log Evidence
Python.log shows no test discovery on startup:
[info] Active interpreter: .venv/bin/python
[info] Starting Pylance language server.
[error] Unable to find workspace for given file
After running Test: Refresh Tests, the log shows:
[info] Environment variables set for pytest discovery: PYTHONPATH=...
[info] Started pytest discovery subprocess for workspace ...
[info] Pytest discovery completed
Additional Context
- Single window scenario (not multi-window)
- pytest works fine from terminal:
python -m pytest --collect-onlysucceeds - Python environment is correctly detected
Extension version: 2026.0.0
VS Code version: Code 1.108.2 (Universal) (c9d77990917f3102ada88be140d28b038d1dd7c7, 2026-01-21T13:52:09.270Z)
OS version: Darwin arm64 25.2.0
Modes:
System Info
| Item | Value |
|---|---|
| CPUs | Apple M3 (8 x 2400) |
| GPU Status | 2d_canvas: enabled direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off trees_in_viz: disabled_off video_decode: enabled video_encode: enabled webgl: enabled webgl2: enabled webgpu: enabled webnn: disabled_off |
| Load (avg) | 2, 2, 2 |
| Memory (System) | 16.00GB (0.11GB free) |
| Process Argv | --crash-reporter-id ea819cd1-e9b8-4654-b394-6ba9979e300c |
| Screen Reader | no |
| VM | 0% |
A/B Experiments
vsliv368:30146709
vswsl492:30256859
binariesv615:30325510
nativeloc1:31344060
dwcopilot:31170013
dwoutputs:31242946
copilot_t_ci:31333650
e5gg6876:31282496
pythonrdcb7:31342333
6518g693:31436602
aj953862:31281341
6abeh943:31336334
envsdeactivate2:31353495
cloudbuttont:31379625
42190218_ostrepl:31403339
use-responses-api:31390855
je187915:31401257
ec5jj548:31422691
cmp-ext-treat:31426748
cp_cls_c_966_ss:31446431
c0683394:31419495
ge8j1254_inline_auto_hint_haiku:31431912
nes-autoexp-10:31446583
a5gib710:31434435
5j92g670_sonnet:31446810
rename_enabled:31436409
7a04d226_do_not_restore_last_panel_session:31438103
anthropic_thinking_t:31432745
h0hdh950:31428394
cp_cls_t_1081:31443828
copilot-nes-oct-trt:31432596
ia-use-proxy-models-svc:31450090
nes-jump-on-with-edit:31450417
nes-slash-models-on:31441832
core-renderer-profiling-on:31440367
nes-set-to-on:31441941
a43f0574a:31442826
ts_provider_disabled:31446105
c0ci8992_validated:31449878
nes-conv-2-3:31447852
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-testingbugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bugconfirmation pendingThe issue needs to be confirmed through a maintainer reproducing the bug.The issue needs to be confirmed through a maintainer reproducing the bug.info-neededIssue requires more information from posterIssue requires more information from poster
Activity
cdeil commentedon Jan 23, 2026
This screenshot shows the issue (no "play" button for tests because pytest discovery didn't run).
I do have a setup where I have a second frontend repo checked out in a sub-folder (and in
.gitignoreor the main Python backend repo). This is withuvas package manager and using also theruffextension in VS Code.There are two errors about not being able to find the workspace for given file in the Python extension log:
But I don't know what the files are and if it's related to the pytest issue. The error does not appear when I open more test files.
Overall it looks like a bug or race condition in
refreshSingleWorkspaceor other workspace-activation related functions in the case where there are two repos involved.jeethesh-pai commentedon Jan 30, 2026
+1 I am also encountering this bug since a month. Did you find any fix? I tried downgrading the Python Extension to 2025 versions but did not help either.
cdeil commentedon Jan 30, 2026
Unfortunately I don't know how to find the root cause or how to find a fix.
Presumably an edge case since I'm sure lots of devs use the VS Code pytest running in many Python projects.
Thomas-Boi commentedon Feb 6, 2026
Not sure if this helps:
jeethesh-pai commentedon Feb 6, 2026
Hi Thomas Bui (@Thomas-Boi) ,
I am also using Pytest for my test runner. In the output tab, I can only see that terminal invokes python interpreter something like
/usr/bin/python3 "import pytest". Thereafter it gets stuck and does not succeed. Even upon restarting test discovery this happens. Whereas if I run pytest from terminal manually all the tests are discovered and run without any problems.eleanorjboyd commentedon Feb 10, 2026
Hi! A few clarifying questions:
python.useEnvironmentsExtensionto false in your settings does this change the behavior?it may be a race condition here but just ttrying to figure out exactly what is triggered so far. Thanks!
jeethesh-pai commentedon Feb 16, 2026
Hi Eleanor Boyd (@eleanorjboyd) ,
Yes, Upon using the "beaker" icon (Testing) does trigger the pytest discovery, but it does not find any test even after waiting for long. In the Output Tab of python, the following gets executed but no discovery.
using
pytestin the command line finds all the tests and executes it without any problems.Also, I can add to the bug that this happens in my case only for devcontainer based code. For the pure python code, it works without any problem.
The setting of `python.useEnvironmentsExtension" was already set to false before, does not resolve the problem either
eleanorjboyd commentedon Feb 17, 2026
hm interesting! Is this your selected environment
/.cache/pypoetry/virtualenvs/hen-cml-utils-xS3fZVNL-py3.10/bin/python? If you try on the newest release of stable (made some changes) do you get anything different or see[test-by-project]in your python logs?jeethesh-pai commentedon Feb 18, 2026
Eleanor Boyd (@eleanorjboyd) yes, that is the environment which I am currently using. This is generated by poetry. But in the terminal the environment do not have any problem executing the
pytestcommand. I am currently using the 2026.2.0 version and I am still getting the same problem as above mentioned. I do not see[test-by-project]anywhere in python logs.eleanorjboyd commentedon Feb 18, 2026
can you try with
python.useEnvironmentsExtension: true- improvements were made for poetry on the environments extension as welljeethesh-pai commentedon Feb 19, 2026
Eleanor Boyd (@eleanorjboyd) Yes, I set the
python.useEnvironmentsExtension: truebut still i am getting this output - nothing happens in the beaker icon.output log from python
2026-02-19 10:24:22.420 [info] > ~/.cache/pypoetry/virtualenvs/venv-name/bin/python -c "import pytest".Is there a way to debug this problem? If i execute the same command in terminal i do not have any problem, it exeuctes.
Here is a verboser output from the python console log -
jeethesh-pai commentedon Feb 26, 2026
Eleanor Boyd (@eleanorjboyd) Is there any updates regarding this?
jeethesh-pai commentedon Feb 27, 2026
Hi Eleanor Boyd (@eleanorjboyd), I have an update here. I somehow fixed this problem in my environment. Here are the steps I used. Please check if this is a problem from VSCode Extension side too.
Problem Cause:
As mentioned above I was not able to get the complete logs like[test-by-project] as you mentioned above. Seems like the reason was a hang caused in sitecustomize.py from /usr/lib/python3.10. Its a default standard package. The initial sitepackage.py looked like this
Root Cause: apport() - Ubuntu's crash reporting tool. When VSCode spawns Python with a restricted process context (no TTY, limited permissions), apport_python_hook.install() hangs trying to register its exception handler with a socket/service that isn't accessible from VSCode's process.
Solution:
The fix is simple — override sitecustomize.py inside the venv so it shadows the system one
Therefore I replaced the system sitecustomize.py to the following:
Note:
sitepackages.pycan be found at<your-venv>/lib/python3.10/site-packages/sitecustomize.py. If this is empty, then complete with the above snippet else replace.This seems to have fixed my pytest discovery. After this the logs came as you mentioned.
Note: Also, installing the package
apport-python-hookalso does not resolve this problem because, the culprit seems to be hanging of theapport_python_hook.install().You can close this if you want, if the fix is not possible from your end. But I will love to get feedback if this was the problem.
github-actions commentedon Apr 13, 2026
Hey Eleanor Boyd (@eleanorjboyd), this issue might need further attention.
Christoph Deil (@cdeil), you can help us out by closing this issue if the problem no longer exists, or adding more information.
github-actions commentedon May 13, 2026
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!