Move test skipping to class setup

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.

Similarly, if the server is not available, entire XMLRPC test classes
are now skipped.

Additionally, CLItests that hit the server are skipped if the server
isn't available.
This commit is contained in:
Petr Viktorin 2012-03-28 04:42:23 -04:00 committed by Rob Crittenden
parent 16b38d39b3
commit 8c1171e923
3 changed files with 17 additions and 7 deletions

View File

@ -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.xmlrpc_uri))
@contextlib.contextmanager
def fake_stdin(self, string_in):

View File

@ -47,8 +47,12 @@ dnsrev2_dn = DN(('idnsname',dnsrev2), revdnszone1_dn)
class test_dns(Declarative):
def setUp(self):
super(test_dns, self).setUp()
@classmethod
def setUpClass(cls):
super(test_dns, cls).setUpClass()
if not api.Backend.xmlclient.isconnected():
api.Backend.xmlclient.connect(fallback=False)
try:
api.Command['dnszone_add'](dnszone1,
idnssoamname = dnszone1_mname,

View File

@ -122,11 +122,13 @@ class XMLRPC_test(object):
Base class for all XML-RPC plugin tests
"""
def setUp(self):
@classmethod
def setUpClass(cls):
if not server_available:
raise nose.SkipTest(
'Server not available: %r' % api.env.xmlrpc_uri
)
raise nose.SkipTest('%r: Server not available: %r' %
(cls.__module__, api.env.xmlrpc_uri))
def setUp(self):
if not api.Backend.xmlclient.isconnected():
api.Backend.xmlclient.connect(fallback=False)