tests: allow logging exceptions on url reach check

This commit is contained in:
RhodeCode Admin 2023-05-11 12:15:48 +02:00
parent ebdcda5477
commit 5c4a45bf59

View file

@ -397,20 +397,21 @@ def wait_for_url(url, timeout=10):
while timeout > last:
last = time.time()
if is_url_reachable(url):
if is_url_reachable(url, log_exc=False):
break
elif (last + wait) > time.time():
# Go to sleep because not enough time has passed since last check.
time.sleep(wait)
else:
pytest.fail("Timeout while waiting for URL {}".format(url))
pytest.fail(f"Timeout while waiting for URL {url}")
def is_url_reachable(url):
def is_url_reachable(url: str, log_exc: bool = True) -> bool:
try:
urllib.request.urlopen(url)
except urllib.error.URLError:
log.exception('URL `{}` reach error'.format(url))
if log_exc:
log.exception('URL `{}` reach error'.format(url))
return False
return True