Skip to content

Commit ad5f5a4

Browse files
Apply review feedback: use anyio.fail_after and simplify exception handling
- Replace asyncio.timeout with anyio.fail_after for consistency - Simplify exception handling logic - Uncomment Windows-specific test skip condition - Auto-format code with ruff
1 parent e64a939 commit ad5f5a4

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

tests/issues/test_552_windows_hang.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import asyncio
21
import sys
32

3+
import anyio
44
import pytest
55

66
from mcp import ClientSession, StdioServerParameters
77
from mcp.client.stdio import stdio_client
88

9-
# @pytest.mark.skipif(sys.platform != "win32", reason="Windows-specific test")
10-
@pytest.mark.skipif(sys.version_info < (3, 11), reason="asyncio.timeout in 3.11+")
9+
10+
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-specific test")
1111
@pytest.mark.parametrize(
1212
"args",
1313
[
@@ -32,19 +32,18 @@ async def test_windows_process_creation(args):
3232
# Directly test the fixed function that was causing the hanging issue
3333
try:
3434
# Set a timeout to prevent hanging
35-
async with asyncio.timeout(5):
35+
with anyio.fail_after(5):
3636
# Test the actual process creation function that was fixed
3737
async with stdio_client(params) as (read, write):
3838
print("inside client")
3939
async with ClientSession(read, write) as c:
4040
print("inside ClientSession")
4141
await c.initialize()
42-
43-
except asyncio.TimeoutError:
42+
except TimeoutError:
4443
pytest.xfail("Process creation timed out, indicating a hang issue")
45-
except ProcessLookupError:
46-
pytest.xfail("Process creation failed with ProcessLookupError")
4744
except Exception as e:
48-
assert "ExceptionGroup" in repr(e), f"Unexpected error: {e}"
49-
assert "ProcessLookupError" in repr(e), f"Unexpected error: {e}"
50-
pytest.xfail(f"Expected error: {e}")
45+
# Simplified exception handling - check for expected errors
46+
if "ProcessLookupError" in repr(e):
47+
pytest.xfail(f"Expected error: {e}")
48+
else:
49+
raise

0 commit comments

Comments
 (0)