From 88453aa46244843c136c53568ed6272600a0ecbc Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 4 Feb 2025 08:16:31 +0100 Subject: [PATCH] [FIX] conftest: assert tunnel response is a proper URL Since the tunnel value is now a path to a script to run (and get the public facing address out of), it's pretty easy to give the path to the wrong program e.g. `--tunnel ngrok` will run ngrok itself, which is going to yield an error message and do nothing, and then break when we try to use the nonsensical result (e.g. an empty string or an error message) as a URL. So assert that the result does parse as a URL-ish with at least a scheme and netloc. --- conftest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/conftest.py b/conftest.py index 8832e860..1cc1fcc8 100644 --- a/conftest.py +++ b/conftest.py @@ -73,6 +73,7 @@ import xmlrpc.client from contextlib import closing from dataclasses import dataclass from typing import Optional +from urllib.parse import urlsplit import pytest import requests @@ -236,7 +237,10 @@ def tunnel(pytestconfig: pytest.Config, port: int): ) as p: # read() blocks forever and I don't know why, read things about the # write end of the stdout pipe still being open here? - yield p.stdout.readline().strip() + result = p.stdout.readline().strip() + url = urlsplit(result) + assert url.scheme and url.netloc + yield url.geturl() p.terminate() p.wait(30) else: