]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
do not run DoH tests if there is no network
authorBob Halley <halley@dnspython.org>
Thu, 21 May 2020 14:43:55 +0000 (07:43 -0700)
committerBob Halley <halley@dnspython.org>
Thu, 21 May 2020 14:48:10 +0000 (07:48 -0700)
tests/test_doh.py

index 51f32ae6647708dc9b526a2662707809f5a7740b..48fa47ea79c7a48ed7cb18f2cd1334abb9e45e56 100644 (file)
@@ -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):