@@ -48,7 +48,8 @@ end_per_testcase(_TestCase, _Config) ->
4848
4949% % Test basic asyncio.sleep timing
5050test_asyncio_sleep (_Config ) ->
51- ok = py :exec (<<"
51+ Ctx = py :context (1 ),
52+ ok = py :exec (Ctx , <<"
5253import asyncio
5354import time
5455
@@ -58,13 +59,14 @@ async def timed_sleep():
5859 return time.monotonic() - start
5960
6061elapsed = asyncio.run(timed_sleep())
61- assert elapsed >= 0.04
62+ assert elapsed >= 0.04, f'Expected >= 0.04s, got {elapsed:.3f}s'
6263" >>),
6364 ok .
6465
6566% % Test asyncio.gather runs tasks concurrently
6667test_asyncio_gather (_Config ) ->
67- ok = py :exec (<<"
68+ Ctx = py :context (1 ),
69+ ok = py :exec (Ctx , <<"
6870import asyncio
6971import time
7072
@@ -76,16 +78,18 @@ async def main():
7678 start = time.monotonic()
7779 r = await asyncio.gather(task(1), task(2), task(3))
7880 elapsed = time.monotonic() - start
79- assert list(r) == [1, 2, 3]
80- assert elapsed < 0.15
81+ assert list(r) == [1, 2, 3], f'Expected [1, 2, 3], got {list(r)}'
82+ # Allow more time on CI (0.3s instead of 0.15s)
83+ assert elapsed < 0.3, f'Expected < 0.3s, got {elapsed:.3f}s'
8184
8285asyncio.run(main())
8386" >>),
8487 ok .
8588
8689% % Test TCP echo server/client using asyncio
8790test_asyncio_tcp_echo (_Config ) ->
88- ok = py :exec (<<"
91+ Ctx = py :context (1 ),
92+ ok = py :exec (Ctx , <<"
8993import asyncio
9094
9195async def handler(r, w):
@@ -106,15 +110,16 @@ async def test():
106110 await w.wait_closed()
107111 srv.close()
108112 await srv.wait_closed()
109- assert resp == b'hello'
113+ assert resp == b'hello', f'Expected b \" hello \" , got {resp}'
110114
111115asyncio.run(test())
112116" >>),
113117 ok .
114118
115119% % Test multiple concurrent TCP connections
116120test_asyncio_concurrent_tcp (_Config ) ->
117- ok = py :exec (<<"
121+ Ctx = py :context (1 ),
122+ ok = py :exec (Ctx , <<"
118123import asyncio
119124
120125async def handler(r, w):
@@ -143,7 +148,7 @@ async def test():
143148 )
144149 srv.close()
145150 await srv.wait_closed()
146- assert set(results) == {b're:1', b're:2', b're:3'}
151+ assert set(results) == {b're:1', b're:2', b're:3'}, f'Expected {{b \" re:1 \" , b \" re:2 \" , b \" re:3 \" }}, got {set(results)}'
147152
148153asyncio.run(test())
149154" >>),
0 commit comments