Skip to content

Commit 84ca24a

Browse files
committed
test: use errno.ENOENT for command not found assertion
- Replace error message text matching with errno.ENOENT check - Improves test reliability across different system languages - Removes dependency on specific error message strings"
1 parent de89457 commit 84ca24a

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

tests/client/test_stdio.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77

88
import anyio
9+
import errno
910
import pytest
1011

1112
from mcp.client.session import ClientSession
@@ -90,17 +91,12 @@ async def test_stdio_client_nonexistent_command():
9091
)
9192

9293
# Should raise an error when trying to start the process
93-
with pytest.raises(Exception) as exc_info:
94+
with pytest.raises(OSError) as exc_info:
9495
async with stdio_client(server_params) as (_, _):
9596
pass
9697

97-
# The error should indicate the command was not found
98-
error_message = str(exc_info.value)
99-
assert (
100-
"nonexistent" in error_message
101-
or "not found" in error_message.lower()
102-
or "cannot find the file" in error_message.lower() # Windows error message
103-
)
98+
# The error should indicate the command was not found (ENOENT: No such file or directory)
99+
assert exc_info.value.errno == errno.ENOENT
104100

105101

106102
@pytest.mark.anyio

0 commit comments

Comments
 (0)