mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Use setup_class/teardown_class in Declarative tests
Pytest will consider each Declarative test individually, running setup/teardown for each one. Move the setup and teardown to the class level. https://fedorahosted.org/freeipa/ticket/4610 Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
parent
84bd4c1246
commit
93c69b5127
@ -52,27 +52,22 @@ class cmdline_test(XMLRPC_test):
|
|||||||
# some reasonable default command
|
# some reasonable default command
|
||||||
command = paths.LS
|
command = paths.LS
|
||||||
|
|
||||||
def setup(self):
|
@classmethod
|
||||||
|
def setup_class(cls):
|
||||||
# Find the executable in $PATH
|
# Find the executable in $PATH
|
||||||
# This is neded because ipautil.run resets the PATH to
|
# This is neded because ipautil.run resets the PATH to
|
||||||
# a system default.
|
# a system default.
|
||||||
original_command = self.command
|
original_command = cls.command
|
||||||
if not os.path.isabs(self.command):
|
if not os.path.isabs(cls.command):
|
||||||
self.command = distutils.spawn.find_executable(self.command)
|
cls.command = distutils.spawn.find_executable(cls.command)
|
||||||
# raise an error if the command is missing even if the remote
|
# raise an error if the command is missing even if the remote
|
||||||
# server is not available.
|
# server is not available.
|
||||||
if not self.command:
|
if not cls.command:
|
||||||
raise AssertionError(
|
raise AssertionError(
|
||||||
'Command %r not available' % original_command
|
'Command %r not available' % original_command
|
||||||
)
|
)
|
||||||
super(cmdline_test, self).setup()
|
super(cmdline_test, cls).setup_class()
|
||||||
if not server_available:
|
if not server_available:
|
||||||
raise nose.SkipTest(
|
raise nose.SkipTest(
|
||||||
'Server not available: %r' % api.env.xmlrpc_uri
|
'Server not available: %r' % api.env.xmlrpc_uri
|
||||||
)
|
)
|
||||||
|
|
||||||
def teardown(self):
|
|
||||||
"""
|
|
||||||
nose tear-down fixture.
|
|
||||||
"""
|
|
||||||
super(cmdline_test, self).teardown()
|
|
||||||
|
@ -34,7 +34,6 @@ class test_changepw(XMLRPC_test, Unauthorized_HTTP_test):
|
|||||||
app_uri = '/ipa/session/change_password'
|
app_uri = '/ipa/session/change_password'
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
super(test_changepw, self).setup()
|
|
||||||
try:
|
try:
|
||||||
api.Command['user_add'](uid=testuser, givenname=u'Test', sn=u'User')
|
api.Command['user_add'](uid=testuser, givenname=u'Test', sn=u'User')
|
||||||
api.Command['passwd'](testuser, password=u'old_password')
|
api.Command['passwd'](testuser, password=u'old_password')
|
||||||
@ -48,7 +47,6 @@ class test_changepw(XMLRPC_test, Unauthorized_HTTP_test):
|
|||||||
api.Command['user_del']([testuser])
|
api.Command['user_del']([testuser])
|
||||||
except errors.NotFound:
|
except errors.NotFound:
|
||||||
pass
|
pass
|
||||||
super(test_changepw, self).teardown()
|
|
||||||
|
|
||||||
def _changepw(self, user, old_password, new_password):
|
def _changepw(self, user, old_password, new_password):
|
||||||
return self.send_request(params={'user': str(user),
|
return self.send_request(params={'user': str(user),
|
||||||
|
@ -84,7 +84,6 @@ class test_cert(XMLRPC_test):
|
|||||||
return ipautil.run(new_args, stdin)
|
return ipautil.run(new_args, stdin)
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
super(test_cert, self).setup()
|
|
||||||
self.reqdir = tempfile.mkdtemp(prefix = "tmp-")
|
self.reqdir = tempfile.mkdtemp(prefix = "tmp-")
|
||||||
self.reqfile = self.reqdir + "/test.csr"
|
self.reqfile = self.reqdir + "/test.csr"
|
||||||
self.pwname = self.reqdir + "/pwd"
|
self.pwname = self.reqdir + "/pwd"
|
||||||
@ -100,7 +99,6 @@ class test_cert(XMLRPC_test):
|
|||||||
self.subject = DN(('CN', self.host_fqdn), x509.subject_base())
|
self.subject = DN(('CN', self.host_fqdn), x509.subject_base())
|
||||||
|
|
||||||
def teardown(self):
|
def teardown(self):
|
||||||
super(test_cert, self).teardown()
|
|
||||||
shutil.rmtree(self.reqdir, ignore_errors=True)
|
shutil.rmtree(self.reqdir, ignore_errors=True)
|
||||||
|
|
||||||
def generateCSR(self, subject):
|
def generateCSR(self, subject):
|
||||||
|
@ -172,15 +172,11 @@ class XMLRPC_test(object):
|
|||||||
if not server_available:
|
if not server_available:
|
||||||
raise nose.SkipTest('%r: Server not available: %r' %
|
raise nose.SkipTest('%r: Server not available: %r' %
|
||||||
(cls.__module__, api.env.xmlrpc_uri))
|
(cls.__module__, api.env.xmlrpc_uri))
|
||||||
|
|
||||||
def setup(self):
|
|
||||||
if not api.Backend.rpcclient.isconnected():
|
if not api.Backend.rpcclient.isconnected():
|
||||||
api.Backend.rpcclient.connect(fallback=False)
|
api.Backend.rpcclient.connect(fallback=False)
|
||||||
|
|
||||||
def teardown(self):
|
@classmethod
|
||||||
"""
|
def teardown_class(cls):
|
||||||
nose tear-down fixture.
|
|
||||||
"""
|
|
||||||
request.destroy_context()
|
request.destroy_context()
|
||||||
|
|
||||||
def failsafe_add(self, obj, pk, **options):
|
def failsafe_add(self, obj, pk, **options):
|
||||||
|
Loading…
Reference in New Issue
Block a user