scripts: pytest: Add option to filter the captured shell output

Sometimes you might need exec_command() to return an value from
running device. If the output contains shell prompts or logger
output, it is harder to capture the value.
Filter away the lines we thing belongs to the shell prompt or
normal logging output.

Signed-off-by: Seppo Takalo <seppo.takalo@nordicsemi.no>
This commit is contained in:
Seppo Takalo 2023-09-18 09:38:49 +03:00 committed by Fabio Baltieri
parent 5452665beb
commit d1f058e65e

View file

@ -66,3 +66,15 @@ class Shell:
# wait for device command execution
lines.extend(self._device.readlines_until(regex=regex_prompt, timeout=timeout, print_output=print_output))
return lines
def get_filtered_output(self, command_lines: list[str]) -> list[str]:
regex_filter = re.compile(
'|'.join([
re.escape(self.prompt),
'<dbg>',
'<inf>',
'<wrn>',
'<err>'
])
)
return list(filter(lambda l: not regex_filter.search(l), command_lines))