-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Type: Bug
When using the "Cancel test run" button to stop the current test, vscode immediately behave as if the test has been canceled, but the underlying process keep running. This can lead in resource contention due to old process keeping lock over resource files.
To compare, running pytest in a command interpreter and sending CTRL-C do terminate the process properly, with pytest logging the test failure and the reason (KeyboardInterrupt).
The issue was previously described in this closed ticket: #7055
I followed the instructions in this comment: #7055 (comment)
But the issue persists.
Steps to reproduce:
Create a file test_bug.py with this content:
def test_loop_forever():
import logging
import os
import time
logger = logging.getLogger("infinite_loop")
logger.error("My PID is: %d", os.getpid())
while True:
time.sleep(10)
logger.error("Still running... PID: %d", os.getpid())Also create a pytest.ini file with this content, to log data to a file:
[pytest]
log_format = %(asctime)s %(name)s %(levelname)s %(message)s
log_date_format = %Y-%m-%d %H:%M:%S
log_file = pytest.log
log_level = DEBUGNow, in the "Testing" view, configure the tests with pytest, and run the created test.
A file pytest.log should be created in the current folder, open it, you should see the PID of the process running the test, as well as a repetition of it every 10 seconds.
In VSCode, in the "Testing" view, click the "Cancel test run" button. VSCode says that the test has been canceled, and no longer show the spinning progress indicator next to the test (as expected).
But, if you look either in Windows task manager, in the "Details" tab, the process with the previously printed PID still exists, and in the log file pytest.log you can see new lines being added.
Diagnostic data
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
2025-07-18 11:57:55.823 [info] arg: --rootdir already exists in args, not adding.
2025-07-18 11:57:55.823 [info] Attempting to use temp directory for test ids file, file name: test-ids-58d69856a7e6d6ec1cff.txt
2025-07-18 11:57:55.846 [info] Environment variables set for pytest execution: PYTHONPATH=C:\Users\USER\scoop\persist\vscode\data\extensions\ms-python.python-2025.10.0-win32-x64\python_files, TEST_RUN_PIPE=\\.\pipe\python-test-results-df28fc97cdc7c1fc4d38, RUN_TEST_IDS_PIPE=C:\Users\USER\AppData\Local\Temp\test-ids-58d69856a7e6d6ec1cff.txt
2025-07-18 11:57:55.846 [info] Running pytest with arguments: C:\Users\USER\scoop\persist\vscode\data\extensions\ms-python.python-2025.10.0-win32-x64\python_files\vscode_pytest\run_pytest_script.py --rootdir=c:\TEMP\aze for workspace c:\TEMP\aze
2025-07-18 11:57:55.846 [info] > C:\TEMP\aze\.venv\Scripts\python.exe ~\scoop\persist\vscode\data\extensions\ms-python.python-2025.10.0-win32-x64\python_files\vscode_pytest\run_pytest_script.py --rootdir=.
2025-07-18 11:57:55.846 [info] cwd: .
2025-07-18 11:58:02.292 [info] Test Result named pipe \\.\pipe\python-test-results-df28fc97cdc7c1fc4d38 cancelled
2025-07-18 11:58:02.292 [info] Test run cancelled, resolving 'TillServerClose' deferred for c:\TEMP\aze.
2025-07-18 11:58:02.292 [info] Test run cancelled, killing pytest subprocess for workspace c:\TEMP\aze
Extension version: 2025.10.0
VS Code version: Code 1.101.2 (2901c5ac6db8a986a5666c3af51ff804d05af0d4, 2025-06-24T20:27:15.391Z)
OS version: Windows_NT x64 10.0.22631
Modes:
- Python version (& distribution if applicable, e.g. Anaconda): 3.13.2
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
- Value of the
python.languageServersetting: Default
User Settings
languageServer: "Pylance"
testing
• pytestArgs: "<placeholder>"
• pytestEnabled: true
experiments
• optInto: ["pythonTestAdapter"]
Installed Extensions
| Extension Name | Extension Id | Version |
|---|---|---|
| black-formatter | ms- | 2025.2.0 |
| cmake-tools | ms- | 1.21.36 |
| copilot | Git | 1.344.0 |
| copilot-chat | Git | 0.28.5 |
| cpptools | ms- | 1.26.3 |
| cpptools-extension-pack | ms- | 1.3.1 |
| cpptools-themes | ms- | 2.0.0 |
| debugpy | ms- | 2025.10.0 |
| even-better-toml | tam | 0.21.2 |
| hexeditor | ms- | 1.11.1 |
| isort | ms- | 2025.0.0 |
| js-debug | ms- | 1.100.1 |
| js-debug-companion | ms- | 1.1.3 |
| powershell | ms- | 2025.2.0 |
| pylint | ms- | 2025.2.0 |
| python | ms- | 2025.10.0 |
| tcl | ras | 0.1.0 |
| vscode-github-actions | git | 0.27.2 |
| vscode-js-profile-table | ms- | 1.0.10 |
| vscode-openapi | 42C | 4.37.2 |
| vscode-pylance | ms- | 2025.6.2 |
| vscode-st | Ser | 1.12.36 |
| vscode-xml | red | 0.29.0 |
| vscode-yaml | red | 1.18.0 |
A/B Experiments
vsliv368:30146709
vswsl492:30256859
binariesv615:30325510
962ge761:31349326
2e7ec940:31000449
nativeloc1:31344060
5fd0e150:31155592
dwcopilot:31170013
471b6256:31263136
6074i472:31201624
dwoutputs:31242946
9064b325:31222308
copilot_t_ci:31333650
e5gg6876:31282496
pythoneinst12:31285622
c7cif404:31314491
pythonpulldiag:31343502
996jf627:31283433
pythonrdcb7:31342333
usemplatestapi:31297334
0aa6g176:31307128
747dc170:31275177
aj953862:31281341
generatesymbolt:31295002
convertfstringf:31295003
pylancequickfixf:31350060
j6a0c355:31346307
usemarketplace:31343026
nesew2to5:31336538
agentclaude:31335815
4f60g487:31327383
nes-diff-11:31337487
992g2967-color:31348502
6abeh943:31336334
yijiwantestdri0626-c:31336931
64bie973:31349831
ji9b5146:31348712
nes-deb-050:31346716