Skip to content

Commit

Permalink
Log warnings for retries
Browse files Browse the repository at this point in the history
  • Loading branch information
bhrutledge committed Feb 27, 2022
1 parent 2e01c5d commit ddb81e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
14 changes: 4 additions & 10 deletions tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def dictfunc():
default_repo.upload(package)


def test_upload_retry(tmpdir, default_repo, capsys):
def test_upload_retry(tmpdir, default_repo, caplog):
"""Print retry messages when the upload response indicates a server error."""
default_repo.disable_progress_bar = True

Expand All @@ -254,33 +254,27 @@ def test_upload_retry(tmpdir, default_repo, capsys):
# Upload with default max_redirects of 5
default_repo.upload(package)

msg = [
assert caplog.messages == [
(
"Uploading fake.whl\n"
'Received "500: Internal server error"\n'
f"Package upload appears to have failed. Retry {i} of 5."
)
for i in range(1, 6)
]

captured = capsys.readouterr()
assert captured.out == "\n".join(msg) + "\n"
caplog.clear()

# Upload with custom max_redirects of 3
default_repo.upload(package, 3)

msg = [
assert caplog.messages == [
(
"Uploading fake.whl\n"
'Received "500: Internal server error"\n'
f"Package upload appears to have failed. Retry {i} of 3."
)
for i in range(1, 4)
]

captured = capsys.readouterr()
assert captured.out == "\n".join(msg) + "\n"


@pytest.mark.parametrize(
"package_meta,repository_url,release_urls",
Expand Down
4 changes: 2 additions & 2 deletions twine/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ def upload(
return resp
if 500 <= resp.status_code < 600:
number_of_redirects += 1
print(
f'[yellow]Received "{resp.status_code}: {resp.reason}"'
logger.warning(
f'Received "{resp.status_code}: {resp.reason}"'
"\nPackage upload appears to have failed."
f" Retry {number_of_redirects} of {max_redirects}."
)
Expand Down

0 comments on commit ddb81e3

Please sign in to comment.