diff --git a/examples/servers/threaded_handlers.py b/examples/servers/threaded_handlers.py index fba9fcdd..9f19ccb2 100644 --- a/examples/servers/threaded_handlers.py +++ b/examples/servers/threaded_handlers.py @@ -20,6 +20,7 @@ """ from __future__ import annotations +import logging import time import threading @@ -93,4 +94,5 @@ def count_down_error(ls: LanguageServer, *args): if __name__ == "__main__": + logging.basicConfig(level=logging.DEBUG) start_server(server) diff --git a/pyproject.toml b/pyproject.toml index a8b6ea03..2389f1c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,7 +67,7 @@ poetry_lock_check = "poetry check" [tool.poe.tasks.test] sequence = [ { cmd = "pytest --cov" }, - { cmd = "pytest tests/e2e --lsp-transport tcp" }, + { cmd = "pytest tests/e2e --lsp-transport tcp --log-cli-level debug" }, ] ignore_fail = "return_non_zero" diff --git a/tests/conftest.py b/tests/conftest.py index fb896f20..f2f74c1d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -19,6 +19,7 @@ from __future__ import annotations import asyncio +import logging import pathlib import sys from typing import Optional @@ -189,6 +190,16 @@ def server_dir(): return path.resolve() +async def forward_stderr(server: asyncio.subprocess.Process): + if server.stderr is None: + return + + # EOF is signalled with an empty bytestring + while (line := await server.stderr.readline()) != b"": + logging.debug(f"[server]: {line.decode('utf8')}") + + + def get_client_for_cpython_server(transport, uri_fixture): """Return a client configured to communicate with a server running under cpython.""" @@ -199,6 +210,7 @@ async def fn( server_cmd = [sys.executable, str(SERVER_DIR / server_name)] server: asyncio.subprocess.Process | None = None + stderr_forwarder = None if transport == "stdio": await client.start_io(*server_cmd) @@ -208,7 +220,8 @@ async def fn( host, port = "localhost", 8888 server_cmd.extend(["--tcp", "--host", host, "--port", f"{port}"]) - server = await asyncio.create_subprocess_exec(*server_cmd) + server = await asyncio.create_subprocess_exec(*server_cmd, stderr=asyncio.subprocess.PIPE) + stderr_forwarder = asyncio.create_task(forward_stderr(server)) await asyncio.sleep(1) await client.start_tcp(host, port) @@ -228,6 +241,10 @@ async def fn( client.exit(None) await client.stop() + + if stderr_forwarder: + stderr_forwarder.cancel() + if server is not None and server.returncode is None: server.terminate()