]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Automatically skip tests that require Internet access if it is not available 166/head
authorScott Kitterman <scott@kitterman.com>
Sat, 28 May 2016 16:46:20 +0000 (12:46 -0400)
committerScott Kitterman <scott@kitterman.com>
Sat, 28 May 2016 16:46:20 +0000 (12:46 -0400)
Add code in tests/test_resolver.py to check if dnspython.org can be looked up by socket.gethostbyname as a test of Internet reachability
Skip tests requiring Internet access (testZoneForName1, testZoneForName2, and testZoneForName3) if it is not available

tests/test_resolver.py

index 29c39594242c78cc6a9fbc55376ab21f437dc255..eb4f23ec7b9a15d6cb33fc62068db8e16fac568c 100644 (file)
@@ -16,6 +16,7 @@
 from io import StringIO
 import select
 import sys
+import socket
 import time
 try:
     import unittest2 as unittest
@@ -30,6 +31,14 @@ import dns.rdatatype
 import dns.resolver
 from dns._compat import xrange
 
+# 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
+
 resolv_conf = u"""
     /t/t
 # comment 1
@@ -86,18 +95,21 @@ class BaseResolverTests(object):
         self.failUnless(cache.get((name, dns.rdatatype.A, dns.rdataclass.IN))
                         is None)
 
+    @unittest.skipIf(not _network_available,"Internet not reachable")
     def testZoneForName1(self):
         name = dns.name.from_text('www.dnspython.org.')
         ezname = dns.name.from_text('dnspython.org.')
         zname = dns.resolver.zone_for_name(name)
         self.failUnless(zname == ezname)
 
+    @unittest.skipIf(not _network_available,"Internet not reachable")
     def testZoneForName2(self):
         name = dns.name.from_text('a.b.www.dnspython.org.')
         ezname = dns.name.from_text('dnspython.org.')
         zname = dns.resolver.zone_for_name(name)
         self.failUnless(zname == ezname)
 
+    @unittest.skipIf(not _network_available,"Internet not reachable")
     def testZoneForName3(self):
         name = dns.name.from_text('dnspython.org.')
         ezname = dns.name.from_text('dnspython.org.')