[Freeipa-devel] [PATCH] 0032 Move DNS test skipping to class setup

Rob Crittenden rcritten at redhat.com
Thu Mar 29 20:18:56 UTC 2012


Petr Viktorin wrote:
>
> Currently, each DNS test case first checks if DNS is configured
> by creating and deleting a test zone. This takes quite a lot of time.
>
> This patch moves the check to the setUpClass method, so the check is
> only done once for all the tests.
>
>
>
> On my VM, this makes the DNS plugin tests 50% faster, saving about half
> a minute for each test run.
>

This fails if the test XML-RPC server is not running. While working on 
that issue I found a few other places that weren't handling this as 
well. Here is my working patch on top of yours.

rob

diff --git a/tests/test_cmdline/test_cli.py b/tests/test_cmdline/test_cli.py
index 889aae4..7e40cf0 100644
--- a/tests/test_cmdline/test_cli.py
+++ b/tests/test_cmdline/test_cli.py
@@ -26,7 +26,11 @@ class TestCLIParsing(object):
          """Run a command on the server"""
          if not api.Backend.xmlclient.isconnected():
              api.Backend.xmlclient.connect(fallback=False)
-        api.Command[command_name](**kw)
+        try:
+            api.Command[command_name](**kw)
+        except errors.NetworkError:
+            raise nose.SkipTest(
+                '%r: Server not available: %r' % (self.__module__, 
api.env.xmlr
pc_uri))

      @contextlib.contextmanager
      def fake_stdin(self, string_in):
diff --git a/tests/test_xmlrpc/test_dns_plugin.py 
b/tests/test_xmlrpc/test_dns_p
lugin.py
index 911c773..2d7a6ea 100644
--- a/tests/test_xmlrpc/test_dns_plugin.py
+++ b/tests/test_xmlrpc/test_dns_plugin.py
@@ -49,6 +49,10 @@ class test_dns(Declarative):

      @classmethod
      def setUpClass(cls):
+        if not api.Backend.xmlclient.isconnected():
+            raise nose.SkipTest(
+                '%r: Server not available: %r' % (cls.__module__, 
api.env.xmlrp
c_uri))
+
          try:
             api.Command['dnszone_add'](dnszone1,
                 idnssoamname = dnszone1_mname,
diff --git a/tests/test_xmlrpc/xmlrpc_test.py 
b/tests/test_xmlrpc/xmlrpc_test.py
index a7cfb11..c0a43ff 100644
--- a/tests/test_xmlrpc/xmlrpc_test.py
+++ b/tests/test_xmlrpc/xmlrpc_test.py
@@ -130,6 +130,13 @@ class XMLRPC_test(object):
          if not api.Backend.xmlclient.isconnected():
              api.Backend.xmlclient.connect(fallback=False)

+    @classmethod
+    def setUpClass(cls):
+        if not server_available:
+            raise nose.SkipTest(
+                '%r: Server not available: %r' % (cls.__module__, 
api.env.xmlrp
c_uri)
+            )
+
      def tearDown(self):
          """
          nose tear-down fixture.




More information about the Freeipa-devel mailing list