Skip to content

Commit

Permalink
Use context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
provinzkraut committed Sep 15, 2024
1 parent a4e2fbc commit a4d8341
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions litestar/testing/client/subprocess_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ def _get_available_port() -> int:
def run_app(workdir: pathlib.Path, app: str) -> Iterator[str]:
"""Launch a litestar application in a subprocess with a random available port."""
port = _get_available_port()
proc = subprocess.Popen(
with subprocess.Popen(
args=["litestar", "--app", app, "run", "--port", str(port)],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
cwd=workdir,
)
url = f"http://127.0.0.1:{port}"
for _ in range(100):
try:
httpx.get(url, timeout=0.1)
break
except httpx.TransportError:
time.sleep(1)
yield url
proc.kill()
) as proc:
url = f"http://127.0.0.1:{port}"
for _ in range(100):
try:
httpx.get(url, timeout=0.1)
break
except httpx.TransportError:
time.sleep(1)
yield url
proc.kill()


@asynccontextmanager
Expand Down

0 comments on commit a4d8341

Please sign in to comment.