tests: allow logging exceptions on url reach check
This commit is contained in:
parent
ebdcda5477
commit
5c4a45bf59
1 changed files with 5 additions and 4 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue