diff --git a/tests/test_repository.py b/tests/test_repository.py index 5526d823..136752c9 100644 --- a/tests/test_repository.py +++ b/tests/test_repository.py @@ -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" @@ -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(