Skip to content

Commit

Permalink
Add retry count to test_links
Browse files Browse the repository at this point in the history
  • Loading branch information
classiqdor committed Jul 11, 2024
1 parent a65e404 commit e76d6f3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/test_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ def iterate_links_from_notebook(filename: str) -> Iterable[tuple[int, str]]:
yield cell_index, url


def _test_single_url(url: str) -> bool:
def _test_single_url(url: str, retry: int = 3) -> bool:
if retry == 0:
return False

headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
}

try:
response = httpx.head(url, headers=headers, follow_redirects=True)

if response.status_code == 403:
# Some flaky error with "doi.org" links
return _test_single_url(url, retry - 1)

return response.is_success
except httpx.HTTPError:
return False

0 comments on commit e76d6f3

Please sign in to comment.