Skip to content

Commit a7ad5b3

Browse files
committed
coverage: add no coverage to platform specific code
Kinda cross but there doesn't seem to be a clean way around it
1 parent c5ef006 commit a7ad5b3

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/mcp/client/stdio/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def _get_executable_command(command: str) -> str:
229229
if sys.platform == "win32": # pragma: no cover
230230
return get_windows_executable_command(command)
231231
else:
232-
return command
232+
return command # pragma: no cover
233233

234234

235235
async def _create_platform_compatible_process(
@@ -254,7 +254,7 @@ async def _create_platform_compatible_process(
254254
stderr=errlog,
255255
cwd=cwd,
256256
start_new_session=True,
257-
)
257+
) # pragma: no cover
258258

259259
return process
260260

@@ -272,7 +272,7 @@ async def _terminate_process_tree(process: Process | FallbackProcess, timeout_se
272272
"""
273273
if sys.platform == "win32": # pragma: no cover
274274
await terminate_windows_process_tree(process, timeout_seconds)
275-
else:
275+
else: # pragma: no cover
276276
# FallbackProcess should only be used for Windows compatibility
277277
assert isinstance(process, Process)
278278
await terminate_posix_process_tree(process, timeout_seconds)

src/mcp/os/posix/utilities.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
POSIX-specific functionality for stdio client operations.
33
"""
4+
# pragma: exclude file
45

56
import logging
67
import os
@@ -23,7 +24,7 @@ async def terminate_posix_process_tree(process: Process, timeout_seconds: float
2324
timeout_seconds: Timeout in seconds before force killing (default: 2.0)
2425
"""
2526
pid = getattr(process, "pid", None) or getattr(getattr(process, "popen", None), "pid", None)
26-
if not pid: # pragma: no cover
27+
if not pid:
2728
# No PID means there's no process to terminate - it either never started,
2829
# already exited, or we have an invalid process object
2930
return
@@ -41,22 +42,20 @@ async def terminate_posix_process_tree(process: Process, timeout_seconds: float
4142
except ProcessLookupError:
4243
return
4344

44-
try: # pragma: no cover
45+
try:
4546
os.killpg(pgid, signal.SIGKILL)
46-
except ProcessLookupError: # pragma: no cover
47+
except ProcessLookupError:
4748
pass
4849

49-
except (ProcessLookupError, PermissionError, OSError) as e: # pragma: no cover
50-
logger.warning(
51-
f"Process group termination failed for PID {pid}: {e}, falling back to simple terminate"
52-
) # pragma: no cover
53-
try: # pragma: no cover
54-
process.terminate() # pragma: no cover
55-
with anyio.fail_after(timeout_seconds): # pragma: no cover
56-
await process.wait() # pragma: no cover
57-
except Exception: # pragma: no cover
58-
logger.warning(f"Process termination failed for PID {pid}, attempting force kill") # pragma: no cover
59-
try: # pragma: no cover
60-
process.kill() # pragma: no cover
61-
except Exception: # pragma: no cover
62-
logger.exception(f"Failed to kill process {pid}") # pragma: no cover
50+
except (ProcessLookupError, PermissionError, OSError) as e:
51+
logger.warning(f"Process group termination failed for PID {pid}: {e}, falling back to simple terminate")
52+
try:
53+
process.terminate()
54+
with anyio.fail_after(timeout_seconds):
55+
await process.wait()
56+
except Exception:
57+
logger.warning(f"Process termination failed for PID {pid}, attempting force kill")
58+
try:
59+
process.kill()
60+
except Exception:
61+
logger.exception(f"Failed to kill process {pid}")

0 commit comments

Comments
 (0)