summaryrefslogtreecommitdiff
path: root/test/py/multiplexed_log.py
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-02-13 08:56:40 -0700
committerSimon Glass <sjg@chromium.org>2023-02-14 09:43:27 -0700
commit7e91bf892fd6f428c7f63cb66287cd94e4c5b989 (patch)
tree8b99aad8ce51df893299745d076240e78924b7b5 /test/py/multiplexed_log.py
parent441a3d0a7a0302ad0292a7b32feb07c3b8143409 (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>
Diffstat (limited to 'test/py/multiplexed_log.py')
-rw-r--r--test/py/multiplexed_log.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py
index 5e79075f2e6..63237594bb4 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')