Skip to content

Commit

Permalink
Rework retries test
Browse files Browse the repository at this point in the history
  • Loading branch information
bhrutledge committed Feb 20, 2022
1 parent ad1259a commit 81749a9
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions tests/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ def dictfunc():

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

default_repo.session = pretend.stub(
post=lambda url, data, allow_redirects, headers: response_with(
status_code=500, reason="Internal server error"
Expand All @@ -254,35 +252,25 @@ def test_upload_retry(tmpdir, default_repo, capsys):
metadata_dictionary=lambda: {"name": "fake"},
)

def assert_retries(output, total):
retries = [line for line in output.splitlines() if line.startswith("Received")]
assert retries == [
(
'Received "500: Internal server error" '
f"Package upload appears to have failed. Retry {i} of {total}"
)
for i in range(1, total + 1)
]

# Upload with default max_redirects of 5
default_repo.upload(package)

msg = [
(
"Uploading fake.whl\n"
'Received "500: Internal server error" '
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"
assert_retries(capsys.readouterr().out, 5)

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

msg = [
(
"Uploading fake.whl\n"
'Received "500: Internal server error" '
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"
assert_retries(capsys.readouterr().out, 3)


@pytest.mark.parametrize(
Expand Down

0 comments on commit 81749a9

Please sign in to comment.