Skip to content

Commit 7b0c949

Browse files
committed
CI: Properly cleanup sessions
1 parent 12e2e72 commit 7b0c949

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

tests/conftest.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import asyncio
21
import socket
32
import threading
43
import time
5-
from collections.abc import Generator
64
from dataclasses import dataclass, field
75

86
import pytest
@@ -11,7 +9,6 @@
119
import swerex.server
1210
from swerex.runtime.abstract import (
1311
BashAction,
14-
CloseBashSessionRequest,
1512
Command,
1613
CreateBashSessionRequest,
1714
)
@@ -55,17 +52,23 @@ def run_server():
5552

5653

5754
@pytest.fixture
58-
def remote_runtime(remote_server: RemoteServer) -> Generator[RemoteRuntime, None]:
55+
async def remote_runtime(remote_server: RemoteServer):
56+
"""Async fixture for RemoteRuntime that properly handles cleanup."""
5957
r = RemoteRuntime(port=remote_server.port, auth_token=TEST_API_KEY)
60-
yield r
61-
asyncio.run(r.close())
58+
try:
59+
yield r
60+
finally:
61+
await r.close()
6262

6363

6464
@pytest.fixture
65-
def runtime_with_default_session(remote_runtime: RemoteRuntime) -> Generator[RemoteRuntime, None]:
66-
asyncio.run(remote_runtime.create_session(CreateBashSessionRequest()))
67-
yield remote_runtime
68-
asyncio.run(remote_runtime.close_session(CloseBashSessionRequest()))
65+
async def runtime_with_default_session(remote_runtime: RemoteRuntime):
66+
"""Async fixture that creates a default session and cleans it up properly."""
67+
await remote_runtime.create_session(CreateBashSessionRequest())
68+
try:
69+
yield remote_runtime
70+
finally:
71+
await remote_runtime.close()
6972

7073

7174
class _Action(BashAction):

0 commit comments

Comments
 (0)