From 5c4a45bf59fcd53724db6dcc264e329fd8ed8f79 Mon Sep 17 00:00:00 2001 From: RhodeCode Admin Date: Thu, 11 May 2023 12:15:48 +0200 Subject: [PATCH] tests: allow logging exceptions on url reach check --- rhodecode/tests/utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rhodecode/tests/utils.py b/rhodecode/tests/utils.py index 30e0401e..97df9681 100644 --- a/rhodecode/tests/utils.py +++ b/rhodecode/tests/utils.py @@ -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