Repository navigation
Closed as not planned
Labels
Description
Type: Bug
Behaviour
Pytesting through UI doesn't work with WSL extension. An error occures when processing data sent from WSL to VScode :
Steps to reproduce:
- Create environnement with hatch (
hatch env run -e dev test) - Select interpreter in VSCode to point on the venv dir ( hatc
h env find dev) - Go to testing in VSCode, and play the test.
- Test pass without error, but the data is not sent back
Output for Python in the Output panel
Running pytest with args: ['-p', 'vscode_pytest', '--rootdir=/home/user/git/', '/home/user/git/app/tests/test_main.py::test_load_config', '/home/user/git/app/tests/test_main.py::test_get_db_connection_postgresql', '/home/user/git/app/tests/test_main.py::test_get_db_connection_mysql', '/home/user/git/app/tests/test_main.py::test_is_database_empty_postgresql', '/home/user/git/app/tests/test_main.py::test_is_database_empty_mysql', '/home/user/git/app/tests/test_main.py::test_execute_sql_file', '/home/user/git/app/tests/test_main.py::test_process_database_when_empty', '/home/user/git/app/tests/test_main.py::test_process_database_exception', '/home/user/git/app/tests/test_main.py::test_main_process_multiple_databases']
============================= test session starts ==============================
platform linux -- Python 3.11.2, pytest-7.4.3, pluggy-1.5.0
rootdir: /home/user/git/
plugins: mock-3.14.0
collected 9 items
app/tests/test_main.py Plugin error, exception thrown while attempting to send data[vscode-pytest]: unsupported operand type(s) for +=: 'int' and 'NoneType'
[vscode-pytest] data:
{"jsonrpc": "2.0", "params": {"cwd": "/home/user/git/", "status": "success", "result": {"/home/user/git/app/tests/test_main.py::test_load_config": {"test": "/home/user/git/app/tests/test_main.py::test_load_config", "outcome": "success", "message": null, "traceback": null, "subtest": null}}, "not_found": null, "error": null}}
(X9)
. [100%]
============================== 9 passed in 0.05s ===============================
Finished running tests!
Extension version: 2025.0.0
VS Code version: Code 1.97.0 (33fc5a94a3f99ebe7087e8fe79fbe1d37a251016, 2025-02-04T22:41:26.688Z)
OS version: Windows_NT x64 10.0.26100
Modes:
Remote OS version: Linux x64 5.15.167.4-microsoft-standard-WSL2
Remote OS version: Linux x64 5.15.167.4-microsoft-standard-WSL2
Remote OS version: Linux x64 5.15.167.4-microsoft-standard-WSL2
- Python version (& distribution if applicable, e.g. Anaconda): 3.11.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
Installed Extensions
| Extension Name | Extension Id | Version |
|---|---|---|
| debugpy | ms- | 2025.0.0 |
| gitlens | eam | 16.3.0 |
| js-debug | ms- | 1.97.0 |
| python | ms- | 2025.0.0 |
| vscode-js-profile-table | ms- | 1.0.10 |
| vscode-pylance | ms- | 2025.2.1 |
System Info
| Item | Value |
|---|---|
| CPUs | Intel(R) Core(TM) Ultra 9 185H (22 x 3072) |
| GPU Status | 2d_canvas: enabled canvas_oop_rasterization: enabled_on 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 video_decode: enabled video_encode: enabled vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: enabled webnn: disabled_off |
| Load (avg) | undefined |
| Memory (System) | 31.46GB (12.42GB free) |
| Process Argv | --crash-reporter-id bb4a69d2-a4d3-44a5-b62b-19c8f9b82470 |
| Screen Reader | no |
| VM | 0% |
| Item | Value |
|---|---|
| Remote | WSL: Debian |
| OS | Linux x64 5.15.167.4-microsoft-standard-WSL2 |
| CPUs | Intel(R) Core(TM) Ultra 9 185H (22 x 0) |
| Memory (System) | 15.35GB (13.51GB free) |
| VM | 0% |
| Item | Value |
|---|---|
| Remote | WSL: Debian |
| OS | Linux x64 5.15.167.4-microsoft-standard-WSL2 |
| CPUs | Intel(R) Core(TM) Ultra 9 185H (22 x 0) |
| Memory (System) | 15.35GB (13.51GB free) |
| VM | 0% |
| Item | Value |
|---|---|
| Remote | WSL: Debian |
| OS | Linux x64 5.15.167.4-microsoft-standard-WSL2 |
| CPUs | Intel(R) Core(TM) Ultra 9 185H (22 x 0) |
| Memory (System) | 15.35GB (13.51GB free) |
| VM | 0% |
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
2e7ec940:31000449
pythontbext0:30879054
cppperfnew:31000557
dwnewjupytercf:31046870
nativerepl1:31139838
pythonrstrctxt:31112756
nativeloc1:31192215
iacca1:31171482
5fd0e150:31155592
dwcopilot:31170013
stablechunks:31184530
6074i472:31201624
9064b325:31222308
copilot_t_ci:31222730
jda6j935:31233686
Activity
eleanorjboyd commentedon Feb 14, 2025
hm looks like it is this line causing the issue
bytes_written += __writer.write(segment)from here. Not sure why looks like there is just a problem writing to the named pipe that is open for communication. Karthik Nadig (@karthiknadig) any ideas here specifically since this is coming from WSL? I can also add in some more logging, potentially the name-pipe vs use of fifo is being incorrectly selected on WSL?martin-s-a commentedon Feb 18, 2025
I'm having a very similar issue since fairly recently. I haven't isolated the specific plugin version, but, in my specific case, seems to happen when running (individually and from UI) unitary tests that make use of
mock_open, which makes sense if the involved lines contain anopen()call.Some time ago I opened issue #24399, but the behaviour described in that issue seems to have been replaced by the one described here.
KinkosPouet commentedon Feb 18, 2025
FYI i did this on a brand new environnement on a new computer.
My code didn't change between my migration from old computer to new one.
I Installed WSL + got my code from my git repo without any changes.
karthiknadig commentedon Feb 18, 2025
Eleanor Boyd (@eleanorjboyd) We need to repro this locally to see what is the error. It is likely a path issue, if the paths are
/mnt/c/style then the vs/tmpthen there could be a difference in how we communicate with those. We need to see the logs on how the paths look like. we need to make sure that in WSL scenarios the path does not use Windows mounted folders for pipes.KinkosPouet commentedon Feb 18, 2025
Karthik Nadig (@karthiknadig) To add some information, in my case, every python files used were in
/home/user/, nothing was put in/mnt/c.karthiknadig commentedon Feb 18, 2025
The issue is not with the python files themselves, we use pipes to communicate between VS Code and pytest. When we create the pipes, in WSL they should be created in
/tmpand not in any location that is/mnt/. My concern is that it might be creating it in the wrong location, leading to a bad pipe stream.github-actions commentedon Mar 21, 2025
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!
1 remaining item
Matheus920 commentedon Mar 22, 2025
I'm having the same issue, and in my case, I'm not using WSL but a Devcontainer that's running on my MacOS.
zvonimir-delas commentedon Mar 24, 2025
+1. Can also confirm removing
mock_opencircumvents the issueeleanorjboyd commentedon Mar 31, 2025
Could others speak on if changing
mock_openfixes there issue? The way we communicate usesopento write to a named-pipe so the way the communication is done could be conflicting with your intended test behaviortechnimakri commentedon Apr 8, 2025
I had the same error message on macOS.:
send data[vscode-pytest]: unsupported operand type(s) for +=: 'int' and 'NoneType'.It was caused by mocking the standard library like so:
I resolved this by scoping the mock to the file being tested:
BallsyWalnuts commentedon Oct 31, 2025
Confirmed that this worked for me as well.
mackenzie-grimes-noaa commentedon Nov 8, 2025
Not a problem specific to VSCode (although maybe VSCode could handle it a bit more gracefully). It's a pytest quirk: pytest-dev/pytest#2180
It seems mocking
builtins.openon a module imported by your unit tests causespytestto throw errors. The above issue was closed bypytestmaintainers in 2018, saying it's inherent to how Python imports work and there's nothing they can do about it.Honestly my workaround was to replace any
builtins.open()activities with a simple custom wrapper function. Then it was easier to assert my wrapper function was called as expected, and I trustopen()will work right without testing it.eleanorjboyd commentedon Nov 14, 2025
This is great to know, thank you for explaining! I think with this information and given pytest closed it upstream it is not something we will support at this time and suggest a work-around like what is listed above. Thanks