@@ -190,14 +190,12 @@ class UnityTestCase(AutopilotTestCase):
190190 return divisor
191191
192192 def _patch_environment(self, key, value):
193− """Wrapper for patching env for either upstart or non-upstart
194− environments.
195−
196− """
193+ """Wrapper for patching env for upstart environment."""
197194 try:
198195 current_value = subprocess.check_output([
199196 "/sbin/initctl",
200197 "get-env",
198+ "--global",
201199 key
202200 ]).rstrip()
203201 except subprocess.CalledProcessError:
@@ -206,7 +204,7 @@ class UnityTestCase(AutopilotTestCase):
206204 subprocess.call([
207205 "/sbin/initctl",
208206 "set-env",
209− "-g",
207+ "--global",
210208 "%s=%s" % (key, value)
211209 ])
212210 self.addCleanup(self._upstart_reset_env, key, current_value)
@@ -219,6 +217,7 @@ class UnityTestCase(AutopilotTestCase):
219217 subprocess.call([
220218 "/sbin/initctl",
221219 "set-env",
220+ "--global",
222221 "%s=%s" % (key, value)
223222 ])
224223
@@ -265,12 +264,7 @@ class UnityTestCase(AutopilotTestCase):
265264 return app_proxy
266265
267266 def _launch_unity_with_upstart(self, binary_path, args):
268− subprocess.call([
269− "/sbin/initctl",
270− "set-env",
271− "-g",
272− "QT_LOAD_TESTABILITY=1"
273− ])
267+ self._patch_environment("QT_LOAD_TESTABILITY", 1)
274268
275269 binary_arg = "BINARY=%s" % binary_path
276270 extra_args = "ARGS=%s" % " ".join(args)
@@ -294,7 +288,6 @@ class UnityTestCase(AutopilotTestCase):
294288
295289 def _cleanup_launching_upstart_unity(self):
296290 logger.info("Cleaning up launching unity")
297− subprocess.call(["/sbin/initctl", "unset-env", "QT_LOAD_TESTABILITY"])
298291
299292 # Workaround for issue: lp:1239491
300293 if model() != "Desktop":