Open piotr-kubiak opened 2 months ago
i will give this a try myself - I am not sure if the problem is multiple connections coming from the multiple runners or an ongoing issue we have seen with named pipes that we are switching off of shortly. I will let you know, thanks!
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!
@karthiknadig @eleanorjboyd Why this issue was closed? I am not aware of any request for more information.
This got accidentally closed due to info-needed
flag. Reopening this.
@karthiknadig If there is anything I can help with, I am more than happy to do so.
@piotr-kubiak @eleanorjboyd and I are working on a fix for a communication problem between python extension. We can share a build when we have it working, and we any help testing this is greatly appreciated.
To summarize, we need to use a communication mechanism that does not use stdio, sockets, and works on detached processes (so no injected streams). We can't use stdio because it is difficult to parse the results and errors out of it, and any structured communication is broken if any package decides to write to stdout on import. sockets can't be used because testing network python packages gets broken by this. We can't use custom streams for IPC to inject into the process, because we don't have control over how it is invoked when running under the debugger.
We have two options left, force pytest to write out a structured result document like Junit, or use an alternative mechanism Named Pipes. Junit method is bad for the reason that you don't have live progress, also, it is complicated to map test ids in Junit to pytest test ids. The last option is Named Pipes, on windows this uses builtin named pipes, but on non-windows this has two implementation UDS (unix domain sockets) and fifo
. UDS is again created on top of sockets, and runs into the same issues with regular sockets. Additionally, with WSL there are two variants of UDS, Win32 UDS and Unix Sockets. We are only left with fifo
for unix and standard named pipes for windows.
Now we come to multi-connection problem, since the two modes of communications are distinct, we did not have a good way to handle multiple connections for both cases. We are exploring, how to handle these for each scenario, we have a rough solution. We will share more details as we get to something that we can share.
Type: Bug
Behaviour
I have the following setup: pyproject.toml:
_testFoo.py:
I have also enabled the
pythonTestAdapter
experiment. When I run this test (using the Testing panel), I get the result:The test is skipped (that is expected, I removed Django to create minimal example, and
pytest-django
skips tests that require Django). Next, I add the-n 4
option topytest
:Now, when I run the test exactly as before, the test fails unexpetedly with error
vscode_pytest.VSCodePytestError: Error attempting to connect to extension named pipe
.Steps to reproduce:
As above.
Diagnostic data
Output for
``` Received JSON data in run script Running pytest with args: ['-p', 'vscode_pytest', '--rootdir=h:\\python\\django-vscode-pytest', 'h:\\python\\django-vscode-pytest\\test_Foo.py::test_pass'] ============================= test session starts ============================= platform win32 -- Python 3.11.7, pytest-8.3.2, pluggy-1.5.0 rootdir: h:\python\django-vscode-pytest configfile: pyproject.toml plugins: django-4.9.0, xdist-3.6.1 created: 4/4 workers 4 workers [1 item] s [100%]Error attempting to connect to extension named pipe \\.\pipe\python-test-results-475b03408672b927dda0-sock[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-475b03408672b927dda0-sock' If you are on a Windows machine, this error may be occurring if any of your tests clear environment variables as they are required to communicate with the extension. Please reference https://docs.pytest.org/en/stable/how-to/monkeypatch.html#monkeypatching-environment-variablesfor the correct way to clear environment variables during testing. Traceback (most recent call last): File "c:\Users\Piotr\.vscode\extensions\ms-python.python-2024.12.2-win32-x64\python_files\vscode_pytest\__init__.py", line 857, in send_post_request __writer.connect() File "c:\Users\Piotr\.vscode\extensions\ms-python.python-2024.12.2-win32-x64\python_files\testing_tools\socket_manager.py", line 24, in connect self._writer = open(self.name, "w", encoding="utf-8") # noqa: SIM115, PTH123 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-475b03408672b927dda0-sock' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "c:\Users\Piotr\.vscode\extensions\ms-python.python-2024.12.2-win32-x64\python_files\vscode_pytest\run_pytest_script.py", line 73, inPython
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)Extension version: 2024.12.2 VS Code version: Code 1.92.2 (fee1edb8d6d72a0ddff41e5f71a671c23ed924b9, 2024-08-14T17:29:30.058Z) OS version: Windows_NT x64 10.0.22631 Modes:
python.languageServer
setting: DefaultUser Settings
``` languageServer: "Pylance" testing • pytestEnabled: true experiments • optInto: ["pythonTestAdapter"] ```
Installed Extensions
|Extension Name|Extension Id|Version| |---|---|---| |JavaScript Debugger|ms-vscode.js-debug|1.92.0| |JavaScript Debugger Companion Extension|ms-vscode.js-debug-companion|1.1.3| |Pylance|ms-python.vscode-pylance|2024.8.2| |Python|ms-python.python|2024.12.3| |Python Debugger|ms-python.debugpy|2024.10.0| |Table Visualizer for JavaScript Profiles|ms-vscode.vscode-js-profile-table|1.0.9|