From ba6f91806a747b05a422684350fca5e50539aaf6 Mon Sep 17 00:00:00 2001 From: Karan Dhaodiyal <256503836+karandhaodiyal28-hash@users.noreply.github.com> Date: Fri, 31 Jul 2026 21:06:45 +0530 Subject: [PATCH] Return the endpoint from listen() with the in-process adapter debugpy.listen(..., in_process_debug_adapter=True) returned None, while the out-of-process path and the documented API both return the (host, port) tuple. That's a problem when you pass port 0, since there's then no way to find out which port was actually chosen. Return the endpoint and set listen.called so the in-process path matches the out-of-process one. Fixes #1656. Signed-off-by: Karan Dhaodiyal <256503836+karandhaodiyal28-hash@users.noreply.github.com> --- src/debugpy/server/api.py | 3 ++- tests/debugpy/test_api.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/debugpy/test_api.py diff --git a/src/debugpy/server/api.py b/src/debugpy/server/api.py index a1de5874..cdd3d3ef 100644 --- a/src/debugpy/server/api.py +++ b/src/debugpy/server/api.py @@ -156,7 +156,8 @@ def listen(address, settrace_kwargs, in_process_debug_adapter=False): block_until_connected=False, **settrace_kwargs ) - return + listen.called = True + return host, port import subprocess diff --git a/tests/debugpy/test_api.py b/tests/debugpy/test_api.py new file mode 100644 index 00000000..768edb99 --- /dev/null +++ b/tests/debugpy/test_api.py @@ -0,0 +1,18 @@ +import pytest + +import debugpy.server.api as _api + + +@pytest.fixture +def no_settrace(monkeypatch): + # Avoid actually starting pydevd; we only care about listen()'s return value. + monkeypatch.setattr(_api, "_settrace", lambda **kwargs: None) + monkeypatch.setattr(_api.listen, "called", False) + + +def test_listen_in_process_returns_endpoint(no_settrace): + # Regression test for #1656: listen(..., in_process_debug_adapter=True) used + # to return None, unlike the out-of-process path which returns (host, port). + endpoint = _api.listen(("127.0.0.1", 5678), in_process_debug_adapter=True) + assert endpoint == ("127.0.0.1", 5678) + assert _api.listen.called is True