You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pytest plugin re-runs all tests if a crash occurs inside a pytest_runtestloop hook when using pytest-xdist #24846
use the test explorer to run the parametrized test:
check the test results tab. notice there are two separate crashes:
INTERNALERROR> Exception: failed running tests with args: ['c:\\Users\\user\\asdf2\\tests\\test_foo.py::test_asdf[0]', 'c:\\Users\\user\\asdf2\\tests\\test_foo.py::test_asdf[1]']
INTERNALERROR> Exception: failed running tests with args: ['c:\\Users\\user\\asdf2']
the first crash is expected, but the second one is not. it seems to be re-running pytest after the crash with the project root as the only argument, which tells pytest to run all tests in the project.
Extension version: 2025.1.2025022102
VS Code version: Code 1.97.2 (e54c774e0add60467559eb0d1e229c6452cf8447, 2025-02-12T23:20:35.343Z)
OS version: Windows_NT x64 10.0.22621
Modes:
changed the title [-]pytest plugin re-runs all tests if a crash occurs inside a `pytest_runtestloop` hook[/-][+]pytest plugin re-runs all tests if a crash occurs inside a `pytest_runtestloop` hook when using pytest-xdist[/+]on Feb 25, 2025
hi! Thanks for the detailed issue. First question, do you get errors during discovery like so:
secondly, I am not able to see the double exception failed running tests with args. Could you update the conftest file to add in the os.getpid() as this will help determine if those are coming from different subprocesses.
# conftest.py
from pytest import hookimpl, PytestPluginManager
import os
def pytest_plugin_registered(plugin: object, manager: PytestPluginManager):
print("pid here", os.getpid())
@hookimpl(tryfirst=True)
def pytest_runtestloop(session):
print(f"inside the runTestloop {os.getpid()}")
print("in the loop")
raise Exception(
f"failed running tests with args: {session.config.args}. {os.getpid()}"
)
hi! Thanks for the detailed issue. First question, do you get errors during discovery like so:
yes i do, sorry i didn't notice that when i was creating my repro, but it prints the following error during collection:
INTERNALERROR> Exception: failed running tests with args: ['tests']
although the issue still occurs when i update the pytest_runtestloop hook to not crash during collection:
frompytestimportSession, hookimpl@hookimpl(tryfirst=True)defpytest_runtestloop(session: Session):
ifnotsession.config.option.collectonly:
raiseException(f'failed running tests with args: {session.config.args}')
secondly, I am not able to see the double exception failed running tests with args. Could you update the conftest file to add in the os.getpid() as this will help determine if those are coming from different subprocesses.
output from collection
pid here 39276
pid here 39276
pid here 39276
pid here 39276
pid here 39276
pid here 39276
pid here 39276
============================= test session starts =============================
platform win32 -- Python 3.13.1, pytest-8.3.4, pluggy-1.5.0
rootdir: c:\Users\user\asdf2
configfile: pyproject.toml
plugins: xdist-3.6.1
collected 2 items
<Dir asdf2>
<Package tests>
<Module test_foo.py>
<Function test_asdf[0]>
<Function test_asdf[1]>
inside the runTestloop 39276
in the loop
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 283, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> ~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 337, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
INTERNALERROR> raise exception.with_traceback(exception.__traceback__)
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\logging.py", line 795, in pytest_runtestloop
INTERNALERROR> return (yield)
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\terminal.py", line 673, in pytest_runtestloop
INTERNALERROR> result = yield
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "c:\Users\user\asdf2\tests\conftest.py", line 14, in pytest_runtestloop
INTERNALERROR> raise Exception(
INTERNALERROR> f"failed running tests with args: {session.config.args}. {os.getpid()}"
INTERNALERROR> )
INTERNALERROR> Exception: failed running tests with args: ['tests']. 39276
========================= 2 tests collected in 0.05s ==========================
Starting now, all test run output will be sent to the Test Result panel, while test discovery output will be sent to the "Python" output channel instead of the "Python Test Log" channel. The "Python Test Log" channel will be deprecated within the next month. See https://github.com/microsoft/vscode-python/wiki/New-Method-for-Output-Handling-in-Python-Testing for details.
output from run
Running pytest with args: ['-p', 'vscode_pytest', '-n', 'auto', '--rootdir=c:\\Users\\user\\asdf2', 'c:\\Users\\user\\asdf2\\tests\\test_foo.py::test_asdf[0]', 'c:\\Users\\user\\asdf2\\tests\\test_foo.py::test_asdf[1]']
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
============================= test session starts =============================
platform win32 -- Python 3.13.1, pytest-8.3.4, pluggy-1.5.0
rootdir: c:\Users\user\asdf2
configfile: pyproject.toml
plugins: xdist-3.6.1
created: 2/2 workers
pid here 37080
pid here 37080
inside the runTestloop 37080
in the loop
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 283, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> ~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 337, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
INTERNALERROR> raise exception.with_traceback(exception.__traceback__)
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\logging.py", line 803, in pytest_runtestloop
INTERNALERROR> return (yield) # Run all the tests.
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\terminal.py", line 673, in pytest_runtestloop
INTERNALERROR> result = yield
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "c:\Users\user\asdf2\tests\conftest.py", line 14, in pytest_runtestloop
INTERNALERROR> raise Exception(
INTERNALERROR> f"failed running tests with args: {session.config.args}. {os.getpid()}"
INTERNALERROR> )
INTERNALERROR> Exception: failed running tests with args: ['c:\\Users\\user\\asdf2\\tests\\test_foo.py::test_asdf[0]', 'c:\\Users\\user\\asdf2\\tests\\test_foo.py::test_asdf[1]']. 37080
Error attempting to connect to extension named pipe \\.\pipe\python-test-results-a05981ec1ca3a05d7460[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-a05981ec1ca3a05d7460'
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.
Error attempting to connect to extension named pipe \\.\pipe\python-test-results-a05981ec1ca3a05d7460[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-a05981ec1ca3a05d7460'
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.
Error[vscode-pytest]: unable to read testIds from temp fileError attempting to connect to extension named pipe \\.\pipe\python-test-results-a05981ec1ca3a05d7460[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-a05981ec1ca3a05d7460'
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
pid here 37080
============================= test session starts =============================
platform win32 -- Python 3.13.1, pytest-8.3.4, pluggy-1.5.0
rootdir: c:\Users\user\asdf2
configfile: pyproject.toml
plugins: xdist-3.6.1
collected 2 items
inside the runTestloop 37080
in the loop
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\__init__.py", line 927, in send_message
INTERNALERROR> __writer = open(TEST_RUN_PIPE, "wb") # noqa: SIM115, PTH123
INTERNALERROR> FileNotFoundError: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-a05981ec1ca3a05d7460'
INTERNALERROR>
INTERNALERROR> The above exception was the direct cause of the following exception:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\run_pytest_script.py", line 64, in <module>
INTERNALERROR> pytest.main(arg_array)
INTERNALERROR> ~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\config\__init__.py", line 175, in main
INTERNALERROR> ret: ExitCode | int = config.hook.pytest_cmdline_main(config=config)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
INTERNALERROR> raise exception.with_traceback(exception.__traceback__)
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 330, in pytest_cmdline_main
INTERNALERROR> return wrap_session(config, _main)
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 318, in wrap_session
INTERNALERROR> config.hook.pytest_sessionfinish(
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
INTERNALERROR> session=session, exitstatus=session.exitstatus
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> )
INTERNALERROR> ^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
INTERNALERROR> raise exception.with_traceback(exception.__traceback__)
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\logging.py", line 868, in pytest_sessionfinish
INTERNALERROR> return (yield)
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\terminal.py", line 893, in pytest_sessionfinish
INTERNALERROR> result = yield
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\warnings.py", line 141, in pytest_sessionfinish
INTERNALERROR> return (yield)
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\__init__.py", line 426, in pytest_sessionfinish
INTERNALERROR> send_execution_message(
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~^
INTERNALERROR> os.fsdecode(cwd),
INTERNALERROR> ^^^^^^^^^^^^^^^^^
INTERNALERROR> exitstatus_bool,
INTERNALERROR> ^^^^^^^^^^^^^^^^
INTERNALERROR> None,
INTERNALERROR> ^^^^^
INTERNALERROR> )
INTERNALERROR> ^
INTERNALERROR> File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\__init__.py", line 871, in send_execution_message
INTERNALERROR> send_message(payload)
INTERNALERROR> ~~~~~~~~~~~~^^^^^^^^^
INTERNALERROR> File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\__init__.py", line 938, in send_message
INTERNALERROR> raise VSCodePytestError(error_msg) from error
INTERNALERROR> vscode_pytest.VSCodePytestError: Error attempting to connect to extension named pipe \\.\pipe\python-test-results-a05981ec1ca3a05d7460[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-a05981ec1ca3a05d7460'
INTERNALERROR>
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 283, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> ~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 337, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
INTERNALERROR> raise exception.with_traceback(exception.__traceback__)
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\logging.py", line 803, in pytest_runtestloop
INTERNALERROR> return (yield) # Run all the tests.
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\terminal.py", line 673, in pytest_runtestloop
INTERNALERROR> result = yield
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "c:\Users\user\asdf2\tests\conftest.py", line 14, in pytest_runtestloop
INTERNALERROR> raise Exception(
INTERNALERROR> f"failed running tests with args: {session.config.args}. {os.getpid()}"
INTERNALERROR> )
INTERNALERROR> Exception: failed running tests with args: ['c:\\Users\\user\\asdf2']. 37080
Error attempting to connect to extension named pipe \\.\pipe\python-test-results-a05981ec1ca3a05d7460[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-a05981ec1ca3a05d7460'
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\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\__init__.py", line 927, in send_message
__writer = open(TEST_RUN_PIPE, "wb") # noqa: SIM115, PTH123
FileNotFoundError: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-a05981ec1ca3a05d7460'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\run_pytest_script.py", line 64, in <module>
pytest.main(arg_array)
~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\config\__init__.py", line 175, in main
ret: ExitCode | int = config.hook.pytest_cmdline_main(config=config)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
raise exception.with_traceback(exception.__traceback__)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
res = hook_impl.function(*args)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 330, in pytest_cmdline_main
return wrap_session(config, _main)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 318, in wrap_session
config.hook.pytest_sessionfinish(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
session=session, exitstatus=session.exitstatus
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
raise exception.with_traceback(exception.__traceback__)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
teardown.throw(exception) # type: ignore[union-attr]
~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\logging.py", line 868, in pytest_sessionfinish
return (yield)
^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
teardown.throw(exception) # type: ignore[union-attr]
~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\terminal.py", line 893, in pytest_sessionfinish
result = yield
^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
teardown.throw(exception) # type: ignore[union-attr]
~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\warnings.py", line 141, in pytest_sessionfinish
return (yield)
^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
res = hook_impl.function(*args)
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\__init__.py", line 426, in pytest_sessionfinish
send_execution_message(
~~~~~~~~~~~~~~~~~~~~~~^
os.fsdecode(cwd),
^^^^^^^^^^^^^^^^^
exitstatus_bool,
^^^^^^^^^^^^^^^^
None,
^^^^^
)
^
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\__init__.py", line 871, in send_execution_message
send_message(payload)
~~~~~~~~~~~~^^^^^^^^^
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\__init__.py", line 938, in send_message
raise VSCodePytestError(error_msg) from error
vscode_pytest.VSCodePytestError: Error attempting to connect to extension named pipe \\.\pipe\python-test-results-a05981ec1ca3a05d7460[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-a05981ec1ca3a05d7460'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\__init__.py", line 927, in send_message
__writer = open(TEST_RUN_PIPE, "wb") # noqa: SIM115, PTH123
FileNotFoundError: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-a05981ec1ca3a05d7460'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\run_pytest_script.py", line 67, in <module>
run_pytest(args)
~~~~~~~~~~^^^^^^
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\run_pytest_script.py", line 23, in run_pytest
pytest.main(arg_array)
~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\config\__init__.py", line 175, in main
ret: ExitCode | int = config.hook.pytest_cmdline_main(config=config)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
raise exception.with_traceback(exception.__traceback__)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
res = hook_impl.function(*args)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 330, in pytest_cmdline_main
return wrap_session(config, _main)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 318, in wrap_session
config.hook.pytest_sessionfinish(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
session=session, exitstatus=session.exitstatus
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
raise exception.with_traceback(exception.__traceback__)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
teardown.throw(exception) # type: ignore[union-attr]
~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\logging.py", line 868, in pytest_sessionfinish
return (yield)
^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
teardown.throw(exception) # type: ignore[union-attr]
~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\terminal.py", line 893, in pytest_sessionfinish
result = yield
^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
teardown.throw(exception) # type: ignore[union-attr]
~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\warnings.py", line 141, in pytest_sessionfinish
return (yield)
^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
res = hook_impl.function(*args)
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\__init__.py", line 426, in pytest_sessionfinish
send_execution_message(
~~~~~~~~~~~~~~~~~~~~~~^
os.fsdecode(cwd),
^^^^^^^^^^^^^^^^^
exitstatus_bool,
^^^^^^^^^^^^^^^^
None,
^^^^^
)
^
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\__init__.py", line 871, in send_execution_message
send_message(payload)
~~~~~~~~~~~~^^^^^^^^^
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.1.2025022501-win32-x64\python_files\vscode_pytest\__init__.py", line 938, in send_message
raise VSCodePytestError(error_msg) from error
vscode_pytest.VSCodePytestError: Error attempting to connect to extension named pipe \\.\pipe\python-test-results-a05981ec1ca3a05d7460[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-a05981ec1ca3a05d7460'
Finished running tests!
Thank you for those details- so it is interesting because the process ID at both exceptions is the main process thread, so it is not being hit in each worker or rerun at that level (from what I can tell). My next guess is maybe workers are rerun by the main process if exceptions occur. Can you try adding this argument and see if that changes anything? pytest -n auto --dist no. Sorry to make you try things I just can't get the behavior to reproduce for me. I am wondering if it is the difference in OS types that might be causing auto attempts at rerunning when exceptions occur? Just a theory tho
Can you try adding this argument and see if that changes anything? pytest -n auto --dist no.
same result
Details
Running pytest with args: ['-p', 'vscode_pytest', '-n', 'auto', '--dist', 'no', '--rootdir=c:\\Users\\user\\\asdf2', 'c:\\Users\\user\\\asdf2\\tests\\test_foo.py::test_asdf[0]', 'c:\\Users\\user\\\asdf2\\tests\\test_foo.py::test_asdf[1]']
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
============================= test session starts =============================
platform win32 -- Python 3.13.1, pytest-8.3.4, pluggy-1.5.0
rootdir: c:\Users\user\asdf2
configfile: pyproject.toml
plugins: xdist-3.6.1
created: 2/2 workers
pid here 4532
pid here 4532
inside the runTestloop 4532
in the loop
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 283, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> ~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 337, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
INTERNALERROR> raise exception.with_traceback(exception.__traceback__)
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\logging.py", line 803, in pytest_runtestloop
INTERNALERROR> return (yield) # Run all the tests.
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\terminal.py", line 673, in pytest_runtestloop
INTERNALERROR> result = yield
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "c:\Users\user\asdf2\tests\conftest.py", line 14, in pytest_runtestloop
INTERNALERROR> raise Exception(
INTERNALERROR> f"failed running tests with args: {session.config.args}. {os.getpid()}"
INTERNALERROR> )
INTERNALERROR> Exception: failed running tests with args: ['c:\\Users\\user\\\asdf2\\tests\\test_foo.py::test_asdf[0]', 'c:\\Users\\user\\\asdf2\\tests\\test_foo.py::test_asdf[1]']. 4532
Error attempting to connect to extension named pipe \\.\pipe\python-test-results-1f5c84f29434e534f7a3[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-1f5c84f29434e534f7a3'
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.
Error attempting to connect to extension named pipe \\.\pipe\python-test-results-1f5c84f29434e534f7a3[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-1f5c84f29434e534f7a3'
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.
Error[vscode-pytest]: unable to read testIds from temp fileError attempting to connect to extension named pipe \\.\pipe\python-test-results-1f5c84f29434e534f7a3[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-1f5c84f29434e534f7a3'
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
pid here 4532
============================= test session starts =============================
platform win32 -- Python 3.13.1, pytest-8.3.4, pluggy-1.5.0
rootdir: c:\Users\user\asdf2
configfile: pyproject.toml
plugins: xdist-3.6.1
collected 2 items
inside the runTestloop 4532
in the loop
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\__init__.py", line 927, in send_message
INTERNALERROR> __writer = open(TEST_RUN_PIPE, "wb") # noqa: SIM115, PTH123
INTERNALERROR> FileNotFoundError: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-1f5c84f29434e534f7a3'
INTERNALERROR>
INTERNALERROR> The above exception was the direct cause of the following exception:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\run_pytest_script.py", line 64, in <module>
INTERNALERROR> pytest.main(arg_array)
INTERNALERROR> ~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\config\__init__.py", line 175, in main
INTERNALERROR> ret: ExitCode | int = config.hook.pytest_cmdline_main(config=config)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
INTERNALERROR> raise exception.with_traceback(exception.__traceback__)
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 330, in pytest_cmdline_main
INTERNALERROR> return wrap_session(config, _main)
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 318, in wrap_session
INTERNALERROR> config.hook.pytest_sessionfinish(
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
INTERNALERROR> session=session, exitstatus=session.exitstatus
INTERNALERROR> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> )
INTERNALERROR> ^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
INTERNALERROR> raise exception.with_traceback(exception.__traceback__)
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\logging.py", line 868, in pytest_sessionfinish
INTERNALERROR> return (yield)
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\terminal.py", line 893, in pytest_sessionfinish
INTERNALERROR> result = yield
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\warnings.py", line 141, in pytest_sessionfinish
INTERNALERROR> return (yield)
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\__init__.py", line 426, in pytest_sessionfinish
INTERNALERROR> send_execution_message(
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~^
INTERNALERROR> os.fsdecode(cwd),
INTERNALERROR> ^^^^^^^^^^^^^^^^^
INTERNALERROR> exitstatus_bool,
INTERNALERROR> ^^^^^^^^^^^^^^^^
INTERNALERROR> None,
INTERNALERROR> ^^^^^
INTERNALERROR> )
INTERNALERROR> ^
INTERNALERROR> File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\__init__.py", line 871, in send_execution_message
INTERNALERROR> send_message(payload)
INTERNALERROR> ~~~~~~~~~~~~^^^^^^^^^
INTERNALERROR> File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\__init__.py", line 938, in send_message
INTERNALERROR> raise VSCodePytestError(error_msg) from error
INTERNALERROR> vscode_pytest.VSCodePytestError: Error attempting to connect to extension named pipe \\.\pipe\python-test-results-1f5c84f29434e534f7a3[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-1f5c84f29434e534f7a3'
INTERNALERROR>
INTERNALERROR> During handling of the above exception, another exception occurred:
INTERNALERROR>
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 283, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> ~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 337, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
INTERNALERROR> return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR> ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
INTERNALERROR> raise exception.with_traceback(exception.__traceback__)
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\logging.py", line 803, in pytest_runtestloop
INTERNALERROR> return (yield) # Run all the tests.
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
INTERNALERROR> teardown.throw(exception) # type: ignore[union-attr]
INTERNALERROR> ~~~~~~~~~~~~~~^^^^^^^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\terminal.py", line 673, in pytest_runtestloop
INTERNALERROR> result = yield
INTERNALERROR> ^^^^^
INTERNALERROR> File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
INTERNALERROR> res = hook_impl.function(*args)
INTERNALERROR> File "c:\Users\user\asdf2\tests\conftest.py", line 14, in pytest_runtestloop
INTERNALERROR> raise Exception(
INTERNALERROR> f"failed running tests with args: {session.config.args}. {os.getpid()}"
INTERNALERROR> )
INTERNALERROR> Exception: failed running tests with args: ['c:\\Users\\user\\\asdf2']. 4532
Error attempting to connect to extension named pipe \\.\pipe\python-test-results-1f5c84f29434e534f7a3[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-1f5c84f29434e534f7a3'
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\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\__init__.py", line 927, in send_message
__writer = open(TEST_RUN_PIPE, "wb") # noqa: SIM115, PTH123
FileNotFoundError: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-1f5c84f29434e534f7a3'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\run_pytest_script.py", line 64, in <module>
pytest.main(arg_array)
~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\config\__init__.py", line 175, in main
ret: ExitCode | int = config.hook.pytest_cmdline_main(config=config)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
raise exception.with_traceback(exception.__traceback__)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
res = hook_impl.function(*args)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 330, in pytest_cmdline_main
return wrap_session(config, _main)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 318, in wrap_session
config.hook.pytest_sessionfinish(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
session=session, exitstatus=session.exitstatus
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
raise exception.with_traceback(exception.__traceback__)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
teardown.throw(exception) # type: ignore[union-attr]
~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\logging.py", line 868, in pytest_sessionfinish
return (yield)
^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
teardown.throw(exception) # type: ignore[union-attr]
~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\terminal.py", line 893, in pytest_sessionfinish
result = yield
^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
teardown.throw(exception) # type: ignore[union-attr]
~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\warnings.py", line 141, in pytest_sessionfinish
return (yield)
^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
res = hook_impl.function(*args)
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\__init__.py", line 426, in pytest_sessionfinish
send_execution_message(
~~~~~~~~~~~~~~~~~~~~~~^
os.fsdecode(cwd),
^^^^^^^^^^^^^^^^^
exitstatus_bool,
^^^^^^^^^^^^^^^^
None,
^^^^^
)
^
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\__init__.py", line 871, in send_execution_message
send_message(payload)
~~~~~~~~~~~~^^^^^^^^^
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\__init__.py", line 938, in send_message
raise VSCodePytestError(error_msg) from error
vscode_pytest.VSCodePytestError: Error attempting to connect to extension named pipe \\.\pipe\python-test-results-1f5c84f29434e534f7a3[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-1f5c84f29434e534f7a3'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\__init__.py", line 927, in send_message
__writer = open(TEST_RUN_PIPE, "wb") # noqa: SIM115, PTH123
FileNotFoundError: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-1f5c84f29434e534f7a3'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\run_pytest_script.py", line 67, in <module>
run_pytest(args)
~~~~~~~~~~^^^^^^
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\run_pytest_script.py", line 23, in run_pytest
pytest.main(arg_array)
~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\config\__init__.py", line 175, in main
ret: ExitCode | int = config.hook.pytest_cmdline_main(config=config)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
raise exception.with_traceback(exception.__traceback__)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
res = hook_impl.function(*args)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 330, in pytest_cmdline_main
return wrap_session(config, _main)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\main.py", line 318, in wrap_session
config.hook.pytest_sessionfinish(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
session=session, exitstatus=session.exitstatus
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_hooks.py", line 513, in __call__
return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_manager.py", line 120, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 139, in _multicall
raise exception.with_traceback(exception.__traceback__)
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
teardown.throw(exception) # type: ignore[union-attr]
~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\logging.py", line 868, in pytest_sessionfinish
return (yield)
^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
teardown.throw(exception) # type: ignore[union-attr]
~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\terminal.py", line 893, in pytest_sessionfinish
result = yield
^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 122, in _multicall
teardown.throw(exception) # type: ignore[union-attr]
~~~~~~~~~~~~~~^^^^^^^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\_pytest\warnings.py", line 141, in pytest_sessionfinish
return (yield)
^^^^^
File "C:\Users\user\asdf2\.venv\Lib\site-packages\pluggy\_callers.py", line 103, in _multicall
res = hook_impl.function(*args)
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\__init__.py", line 426, in pytest_sessionfinish
send_execution_message(
~~~~~~~~~~~~~~~~~~~~~~^
os.fsdecode(cwd),
^^^^^^^^^^^^^^^^^
exitstatus_bool,
^^^^^^^^^^^^^^^^
None,
^^^^^
)
^
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\__init__.py", line 871, in send_execution_message
send_message(payload)
~~~~~~~~~~~~^^^^^^^^^
File "c:\Users\user\.vscode\extensions\ms-python.python-2025.3.2025031001-win32-x64\python_files\vscode_pytest\__init__.py", line 938, in send_message
raise VSCodePytestError(error_msg) from error
vscode_pytest.VSCodePytestError: Error attempting to connect to extension named pipe \\.\pipe\python-test-results-1f5c84f29434e534f7a3[vscode-pytest]: [Errno 2] No such file or directory: '\\\\.\\pipe\\python-test-results-1f5c84f29434e534f7a3'
Finished running tests!
Sorry to make you try things I just can't get the behavior to reproduce for me.
no worries, thanks for taking the time to investigate
I am wondering if it is the difference in OS types that might be causing auto attempts at rerunning when exceptions occur? Just a theory tho
i'm on windows 11, let me know if you need any more details and i will try to provide them
#24307 (comment) has reproduction details for a likely duplicate issue that I reported in October. The reason for that issue (and like this one here, too) is fundamentally flawed logic here:
print("Running pytest with args: "+str(arg_array))
pytest.main(arg_array)
exceptExceptionase:
print("Error[vscode-pytest]: unable to read testIds from temp file"+str(e))
run_pytest(args)
Sorry to be so blunt, but I really wonder why anyone still spends time investigating follow-up issues rather than fixing the original issue that has been for half a year, added reproduction steps, analyzed, and proposed a solution.
Sorry to be so blunt, but I really wonder why anyone still spends time investigating follow-up issues rather than fixing the original issue that has been for half a year, added reproduction steps, analyzed, and proposed a solution.
i did see your issue before i opened this one but i wasn't certain it was the same issue which is why i raised a separate one and linked it as a potentially related issue. reading your issue again more carefully i see now that they are very likely to be the same underlying issue, so i'll close mine as a duplicate
Activity
DetachHead commentedon Feb 25, 2025
possibly related issues:
[-]pytest plugin re-runs all tests if a crash occurs inside a `pytest_runtestloop` hook[/-][+]pytest plugin re-runs all tests if a crash occurs inside a `pytest_runtestloop` hook when using pytest-xdist[/+]eleanorjboyd commentedon Mar 3, 2025
hi! Thanks for the detailed issue. First question, do you get errors during discovery like so:
secondly, I am not able to see the double exception
failed running tests with args. Could you update the conftest file to add in the os.getpid() as this will help determine if those are coming from different subprocesses.DetachHead commentedon Mar 4, 2025
yes i do, sorry i didn't notice that when i was creating my repro, but it prints the following error during collection:
although the issue still occurs when i update the
pytest_runtestloophook to not crash during collection:output from collection
output from run
eleanorjboyd commentedon Mar 4, 2025
Thank you for those details- so it is interesting because the process ID at both exceptions is the main process thread, so it is not being hit in each worker or rerun at that level (from what I can tell). My next guess is maybe workers are rerun by the main process if exceptions occur. Can you try adding this argument and see if that changes anything?
pytest -n auto --dist no. Sorry to make you try things I just can't get the behavior to reproduce for me. I am wondering if it is the difference in OS types that might be causing auto attempts at rerunning when exceptions occur? Just a theory thoDetachHead commentedon Mar 17, 2025
same result
Details
no worries, thanks for taking the time to investigate
i'm on windows 11, let me know if you need any more details and i will try to provide them
bersbersbers commentedon Mar 21, 2025
#24307 (comment) has reproduction details for a likely duplicate issue that I reported in October. The reason for that issue (and like this one here, too) is fundamentally flawed logic here:
vscode-python/python_files/vscode_pytest/run_pytest_script.py
Lines 63 to 67 in 6a60c92
Sorry to be so blunt, but I really wonder why anyone still spends time investigating follow-up issues rather than fixing the original issue that has been for half a year, added reproduction steps, analyzed, and proposed a solution.
DetachHead commentedon Mar 21, 2025
i did see your issue before i opened this one but i wasn't certain it was the same issue which is why i raised a separate one and linked it as a potentially related issue. reading your issue again more carefully i see now that they are very likely to be the same underlying issue, so i'll close mine as a duplicate