scripts: twister: harness: pytest: add support for custom cmd line args

Add support for passing custom command line arguments to a pytest
harness in twister.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
Henrik Brix Andersen 2022-02-24 12:45:29 +01:00 committed by Anas Nashif
commit 7249dab0c8
3 changed files with 19 additions and 1 deletions

View file

@ -369,11 +369,14 @@ harness_config: <harness configuration options>
Only one fixture can be defined per testcase.
pytest_root: <pytest dirctory> (default pytest)
pytest_root: <pytest directory> (default pytest)
Specify a pytest directory which need to excute when test case begin to running,
default pytest directory name is pytest, after pytest finished, twister will
check if this case pass or fail according the pytest report.
pytest_args: <list of arguments> (default empty)
Specify a list of additional arguments to pass to ``pytest``.
The following is an example yaml file with a few harness_config options.
::

View file

@ -131,11 +131,13 @@ class Pytest(Harness):
self.running_dir = instance.build_dir
self.source_dir = instance.testcase.source_dir
self.pytest_root = 'pytest'
self.pytest_args = []
self.is_pytest = True
config = instance.testcase.harness_config
if config:
self.pytest_root = config.get('pytest_root', 'pytest')
self.pytest_args = config.get('pytest_args', [])
def handle(self, line):
''' Test cases that make use of pytest more care about results given
@ -164,6 +166,9 @@ class Pytest(Harness):
'-q'
]
for arg in self.pytest_args:
cmd.append(arg)
log = open(log_file, "a")
outs = []
errs = []

View file

@ -65,6 +65,11 @@ mapping:
"pytest_root":
type: str
required: false
"pytest_args":
type: seq
required: false
sequence:
- type: str
"regex":
type: seq
required: false
@ -193,6 +198,11 @@ mapping:
"pytest_root":
type: str
required: false
"pytest_args":
type: seq
required: false
sequence:
- type: str
"regex":
type: seq
required: false