Tomas Valenta 88266d6ae6
Unify passing of template used in tests and log background commands output (#704)
- Show errors from background commands
- Unify passing of template used in tests
2025-05-06 00:55:03 -07:00

25 lines
617 B
Python

import httpx
from time import sleep
def test_ping_server(sandbox, debug, helpers):
cmd = sandbox.commands.run("python -m http.server 8001", background=True)
try:
host = sandbox.get_host(8001)
status_code = None
for _ in range(20):
res = httpx.get(f"{'http' if debug else 'https'}://{host}")
status_code = res.status_code
if res.status_code == 200:
break
sleep(0.5)
assert status_code == 200
except Exception as e:
helpers.check_cmd_exit_error(cmd)
raise e
finally:
cmd.kill()