add failing test for HTMLPage.get_page raising RetryError
import os.path
import pytest
-from pip._vendor import html5lib
+from mock import Mock
+from pip._vendor import html5lib, requests
from pip._internal.download import PipSession
from pip._internal.index import (
- Link, PackageFinder, _determine_base_url, egg_info_matches,
+ HTMLPage, Link, PackageFinder, _determine_base_url, egg_info_matches,
)
@@ -190,3 +191,22 @@ def test_egg_info_matches(egg_info, search_name, expected):
link = None # Only used for reporting.
version = egg_info_matches(egg_info, search_name, link)
assert version == expected
+
+
+@pytest.mark.parametrize(
+ ('exception', 'message'),
+ [
+ (requests.HTTPError, 'Http error'),
+ (requests.exceptions.RetryError, 'Retry error'),
+ ],
+)
+def test_request_retries(exception, message, caplog):
+ link = Link('http://localhost')
+ session = Mock(PipSession)
+ session.get.return_value = resp = Mock()
+ resp.raise_for_status.side_effect = exception(message)
+ assert HTMLPage.get_page(link, session=session) is None
+ assert (
+ 'Could not fetch URL http://localhost: %s - skipping' % message
+ in caplog.text
+ )
