From 6405207dbf13b53cee87ceffd6ff6e05ef257007 Mon Sep 17 00:00:00 2001 From: Bob Halley Date: Thu, 21 May 2020 07:43:55 -0700 Subject: [PATCH] do not run DoH tests if there is no network --- tests/test_doh.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/test_doh.py b/tests/test_doh.py index 51f32ae6..48fa47ea 100644 --- a/tests/test_doh.py +++ b/tests/test_doh.py @@ -16,6 +16,7 @@ # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. import unittest import random +import socket import dns.query import dns.rdatatype @@ -30,7 +31,15 @@ KNOWN_ANYCAST_DOH_RESOLVER_URLS = ['https://cloudflare-dns.com/dns-query', 'https://dns.google/dns-query', 'https://dns11.quad9.net/dns-query'] -@unittest.skipUnless(dns.query.have_doh, +# Some tests require the internet to be available to run, so let's +# skip those if it's not there. +_network_available = True +try: + socket.gethostbyname('dnspython.org') +except socket.gaierror: + _network_available = False + +@unittest.skipUnless(dns.query.have_doh and _network_available, "Python requests cannot be imported; no DNS over HTTPS (DOH)") class DNSOverHTTPSTestCase(unittest.TestCase): def setUp(self): -- 2.47.3