From e63b4cb9a57f9b941309e587ac335312a6ca9339 Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sat, 29 Mar 2014 14:03:15 +0000 Subject: [PATCH] Add option to disable the Resolver tests with an environment variable. The resolver tests depend on external network resources; the twisted resolver will time out when the network is unvailable instead of returning an immediate failure like the other implementations. --- tornado/test/netutil_test.py | 7 ++++++- tornado/test/util.py | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tornado/test/netutil_test.py b/tornado/test/netutil_test.py index 89d782e6e..bae9da383 100644 --- a/tornado/test/netutil_test.py +++ b/tornado/test/netutil_test.py @@ -10,7 +10,7 @@ import time from tornado.netutil import BlockingResolver, ThreadedResolver, is_valid_ip, bind_sockets from tornado.stack_context import ExceptionStackContext from tornado.testing import AsyncTestCase, gen_test -from tornado.test.util import unittest +from tornado.test.util import unittest, skipIfNoNetwork try: from concurrent import futures @@ -74,12 +74,14 @@ class _ResolverTestMixin(object): socket.AF_UNSPEC) +@skipIfNoNetwork class BlockingResolverTest(AsyncTestCase, _ResolverTestMixin): def setUp(self): super(BlockingResolverTest, self).setUp() self.resolver = BlockingResolver(io_loop=self.io_loop) +@skipIfNoNetwork @unittest.skipIf(futures is None, "futures module not present") class ThreadedResolverTest(AsyncTestCase, _ResolverTestMixin): def setUp(self): @@ -91,6 +93,7 @@ class ThreadedResolverTest(AsyncTestCase, _ResolverTestMixin): super(ThreadedResolverTest, self).tearDown() +@skipIfNoNetwork @unittest.skipIf(futures is None, "futures module not present") class ThreadedResolverImportTest(unittest.TestCase): def test_import(self): @@ -116,6 +119,7 @@ class ThreadedResolverImportTest(unittest.TestCase): self.fail("import timed out") +@skipIfNoNetwork @unittest.skipIf(pycares is None, "pycares module not present") class CaresResolverTest(AsyncTestCase, _ResolverTestMixin): def setUp(self): @@ -123,6 +127,7 @@ class CaresResolverTest(AsyncTestCase, _ResolverTestMixin): self.resolver = CaresResolver(io_loop=self.io_loop) +@skipIfNoNetwork @unittest.skipIf(twisted is None, "twisted module not present") @unittest.skipIf(getattr(twisted, '__version__', '0.0') < "12.1", "old version of twisted") class TwistedResolverTest(AsyncTestCase, _ResolverTestMixin): diff --git a/tornado/test/util.py b/tornado/test/util.py index 360431040..8db413788 100644 --- a/tornado/test/util.py +++ b/tornado/test/util.py @@ -17,3 +17,8 @@ skipIfNonUnix = unittest.skipIf(os.name != 'posix' or sys.platform == 'cygwin', # timing-related tests unreliable. skipOnTravis = unittest.skipIf('TRAVIS' in os.environ, 'timing tests unreliable on travis') + +# Set the environment variable NO_NETWORK=1 to disable any tests that +# depend on an external network. +skipIfNoNetwork = unittest.skipIf('NO_NETWORK' in os.environ, + 'network access disabled') -- 2.47.2