From 02683aecd7b1cba571676e246544442bd3dcf380 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Fri, 18 Jul 2014 13:58:15 +0100 Subject: [PATCH] Unittest - Make is easier to reset env vars of task and taskd --- test/basetest/task.py | 19 ++++++++++++------- test/basetest/taskd.py | 14 ++++++++++---- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/test/basetest/task.py b/test/basetest/task.py index 501e84df6..976ae2b7d 100644 --- a/test/basetest/task.py +++ b/test/basetest/task.py @@ -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) diff --git a/test/basetest/taskd.py b/test/basetest/taskd.py index c67ff3a6d..b2e414999 100644 --- a/test/basetest/taskd.py +++ b/test/basetest/taskd.py @@ -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.