Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest plugin re-runs all tests if a crash occurs inside a pytest_runtestloop hook when using pytest-xdist #24846

Open
DetachHead opened this issue Feb 25, 2025 · 5 comments
Assignees
Labels
triage-needed Needs assignment to the proper sub-team

Comments

@DetachHead
Copy link

DetachHead commented Feb 25, 2025

Type: Bug

Behaviour

when a crash occurs inside a pytest_runtestloop hook while the xdist plugin is active, it will attempt to re-run all tests.

Steps to reproduce:

  1. create the following files:

    # tests/test_foo.py
    
    from pytest import mark
    
    
    @mark.parametrize('i', list(range(2)))
    def test_asdf(i: int):
        pass
    # tests/conftest.py
    
    from pytest import Session, hookimpl
    
    @hookimpl(tryfirst=True)
    def pytest_runtestloop(session: Session):
        raise Exception(f'failed running tests with args: {session.config.args}')
    // .vscode/settings.json
    
    {
        "python.testing.pytestArgs": [
            "tests", "-n", "auto"
        ],
        "python.testing.unittestEnabled": false,
        "python.testing.pytestEnabled": true
    }
  2. use the test explorer to run the parametrized test:
    Image

  3. 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:

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label Feb 25, 2025
@DetachHead DetachHead 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 Feb 25, 2025
@eleanorjboyd
Copy link
Member

eleanorjboyd commented Mar 3, 2025

hi! Thanks for the detailed issue. First question, do you get errors during discovery like so:

Image

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()}"
    )

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Mar 3, 2025
@DetachHead
Copy link
Author

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:

from pytest import Session, hookimpl

@hookimpl(tryfirst=True)
def pytest_runtestloop(session: Session):
    if not session.config.option.collectonly:
        raise Exception(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!

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Mar 4, 2025
@eleanorjboyd
Copy link
Member

eleanorjboyd commented 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 tho

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Mar 4, 2025
@DetachHead
Copy link
Author

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

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

2 participants