Unittest - Make is easier to reset env vars of task and taskd

This commit is contained in:
Renato Alves 2014-07-18 13:58:15 +01:00
parent 2a198d59fe
commit 02683aecd7
2 changed files with 22 additions and 11 deletions

View file

@ -37,13 +37,7 @@ class Task(object):
# Ensure any instance is properly destroyed at session end
atexit.register(lambda: self.destroy())
# Copy all env variables to avoid clashing subprocess environments
self.env = os.environ.copy()
# Make sure no TASKDDATA is isolated
self.env["TASKDATA"] = self.datadir
# As well as TASKRC
self.env["TASKRC"] = self.taskrc
self.reset_env()
# Cannot call self.config until confirmation is disabled
with open(self.taskrc, 'w') as rc:
@ -58,6 +52,17 @@ class Task(object):
txt = super(Task, self).__repr__()
return "{0} running from {1}>".format(txt[:-1], self.datadir)
def reset_env(self):
"""Set a new environment derived from the one used to launch the test
"""
# Copy all env variables to avoid clashing subprocess environments
self.env = os.environ.copy()
# Make sure no TASKDDATA is isolated
self.env["TASKDATA"] = self.datadir
# As well as TASKRC
self.env["TASKRC"] = self.taskrc
def __call__(self, *args, **kwargs):
"aka t = Task() ; t() which is now an alias to t.runSuccess()"
return self.runSuccess(*args, **kwargs)

View file

@ -57,10 +57,7 @@ class Taskd(object):
# Ensure any instance is properly destroyed at session end
atexit.register(lambda: self.destroy())
# Copy all env variables to avoid clashing subprocess environments
self.env = os.environ.copy()
# Make sure TASKDDATA points to the temporary folder
self.env["TASKDATA"] = self.datadir
self.reset_env()
if certpath is None:
certpath = DEFAULT_CERT_PATH
@ -101,6 +98,15 @@ class Taskd(object):
txt = super(Taskd, self).__repr__()
return "{0} running from {1}>".format(txt[:-1], self.datadir)
def reset_env(self):
"""Set a new environment derived from the one used to launch the test
"""
# Copy all env variables to avoid clashing subprocess environments
self.env = os.environ.copy()
# Make sure TASKDDATA points to the temporary folder
self.env["TASKDATA"] = self.datadir
def create_user(self, user=None, group=None, org=None):
"""Create a user/group in the server and return the user
credentials to use in a taskw client.