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>
diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py
index c4fc23a..9e161fb 100644
--- a/test/py/u_boot_utils.py
+++ b/test/py/u_boot_utils.py
@@ -157,7 +157,7 @@
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 @@
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 @@
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