diff options
| author | Benjamin Drung <bdrung@ubuntu.com> | 2022-05-16 12:59:58 +0200 |
|---|---|---|
| committer | Benjamin Drung <bdrung@ubuntu.com> | 2022-05-16 12:59:58 +0200 |
| commit | 220a6d8e93386bc64d3bdb6b15384ec7e7ad5b8f (patch) | |
| tree | 7594cfb6984c1a7371a205b08b90ea1068cf5219 /tests | |
| parent | 0b7f5fe05b157164d0fad543bceb483e07abffde (diff) | |
| download | dnspython-220a6d8e93386bc64d3bdb6b15384ec7e7ad5b8f.tar.gz | |
Allow skipping test cases that need Internet access
Support skipping all test cases that access the Internet by setting the
environment variable `NO_INTERNET`. This is useful to make the test run
reproducible and robust for future runs (to avoid breaking in case some
random service on the Internet changes).
Signed-off-by: Benjamin Drung <bdrung@ubuntu.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/util.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/tests/util.py b/tests/util.py index c8f9704..ffce722 100644 --- a/tests/util.py +++ b/tests/util.py @@ -17,7 +17,7 @@ import enum import inspect -import os.path +import os import socket # Cache for is_internet_reachable() @@ -31,15 +31,19 @@ def here(filename): def is_internet_reachable(): """Check if the Internet is reachable. - The result is cached. + Setting the environment variable `NO_INTERNET` will let this + function always return False. The result is cached. """ global _internet_reachable if _internet_reachable is None: - try: - socket.gethostbyname("dnspython.org") - _internet_reachable = True - except socket.gaierror: + if os.environ.get("NO_INTERNET"): _internet_reachable = False + else: + try: + socket.gethostbyname("dnspython.org") + _internet_reachable = True + except socket.gaierror: + _internet_reachable = False return _internet_reachable |
