Fix internet connectivity test

Signed-off-by: Dan Ryan <dan@danryan.co>
This commit is contained in:
Dan Ryan
2019-03-11 19:42:06 -04:00
parent 8fdc589d05
commit 73129d8401
2 changed files with 34 additions and 10 deletions
+17 -1
View File
@@ -2,7 +2,23 @@
addopts = -ra -n auto
testpaths = tests
; Add vendor and patched in addition to the default list of ignored dirs
norecursedirs = .* build dist CVS _darcs {arch} *.egg vendor patched news tasks docs tests/test_artifacts
; Additionally, ignore tasks, news, test subdirectories and peeps directory
norecursedirs =
.* build
dist
CVS
_darcs
{arch}
*.egg
vendor
patched
news
tasks
docs
tests/test_artifacts
tests/pytest-pypi
tests/pypi
peeps
filterwarnings =
ignore::DeprecationWarning
ignore::PendingDeprecationWarning
+17 -9
View File
@@ -23,16 +23,24 @@ warnings.simplefilter("default", category=ResourceWarning)
HAS_WARNED_GITHUB = False
def try_internet(url="http://httpbin.org/ip", timeout=1.5):
resp = requests.get(url, timeout=timeout)
resp.raise_for_status()
def check_internet():
try:
# Kenneth represents the Internet LGTM.
resp = requests.get('http://httpbin.org/ip', timeout=1.0)
resp.raise_for_status()
except Exception:
warnings.warn('Cannot connect to HTTPBin...', RuntimeWarning)
warnings.warn('Will skip tests requiring Internet', RuntimeWarning)
return False
return True
has_internet = False
for url in ("http://httpbin.org/ip", "http://clients3.google.com/generate_204"):
try:
try_internet(url)
except Exception:
warnings.warn(
"Failed connecting to internet: {0}".format(url), RuntimeWarning
)
else:
has_internet = True
break
return has_internet
def check_github_ssh():