summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-04-10 21:22:06 +0530
committerPraneeth Bajjuri <praneeth@ti.com>2023-04-12 11:48:43 -0500
commit5e2e0db1b68d78315824136f677d01a02ff8a3af (patch)
tree7b2dfd40bfd204e9b64ed31e1ed014e999725838 /test
parent1b4e25eb2861fe62534450d147dfb05545511e6f (diff)
test: Add a way to set the environment for a pytest
This is useful when we need to control a particular environment variable. Add a way to handle this. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
Diffstat (limited to 'test')
-rw-r--r--test/py/multiplexed_log.py5
-rw-r--r--test/py/u_boot_utils.py5
2 files changed, 6 insertions, 4 deletions
diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py
index 5e79075f2e..63237594bb 100644
--- a/test/py/multiplexed_log.py
+++ b/test/py/multiplexed_log.py
@@ -111,7 +111,7 @@ class RunAndLog(object):
"""Clean up any resources managed by this object."""
pass
- def run(self, cmd, cwd=None, ignore_errors=False, stdin=None):
+ def run(self, cmd, cwd=None, ignore_errors=False, stdin=None, env=None):
"""Run a command as a sub-process, and log the results.
The output is available at self.output which can be useful if there is
@@ -126,6 +126,7 @@ class RunAndLog(object):
or exits with an error code, otherwise an exception will be
raised if such problems occur.
stdin: Input string to pass to the command as stdin (or None)
+ env: Environment to use, or None to use the current one
Returns:
The output as a string.
@@ -139,7 +140,7 @@ class RunAndLog(object):
try:
p = subprocess.Popen(cmd, cwd=cwd,
stdin=subprocess.PIPE if stdin else None,
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
(stdout, stderr) = p.communicate(input=stdin)
if stdout is not None:
stdout = stdout.decode('utf-8')
diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py
index c4fc23aeda..9e161fbc23 100644
--- a/test/py/u_boot_utils.py
+++ b/test/py/u_boot_utils.py
@@ -157,7 +157,7 @@ def wait_until_file_open_fails(fn, ignore_errors):
return
raise Exception('File can still be opened')
-def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None):
+def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None, env=None):
"""Run a command and log its output.
Args:
@@ -170,6 +170,7 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None):
an error code, otherwise an exception will be raised if such
problems occur.
stdin: Input string to pass to the command as stdin (or None)
+ env: Environment to use, or None to use the current one
Returns:
The output as a string.
@@ -177,7 +178,7 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None):
if isinstance(cmd, str):
cmd = cmd.split()
runner = u_boot_console.log.get_runner(cmd[0], sys.stdout)
- output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin)
+ output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin, env=env)
runner.close()
return output