twister: pytest: Allow using pytest-args from command file and yaml

Extend pytest-args from configuration yaml file with args
from command line instead of overwriting.

Signed-off-by: Grzegorz Chwierut <grzegorz.chwierut@nordicsemi.no>
This commit is contained in:
Grzegorz Chwierut 2024-07-15 15:48:29 +02:00 committed by Anas Nashif
commit 7cca59c81a
4 changed files with 7 additions and 9 deletions

View file

@ -97,6 +97,8 @@ There are two ways for passing extra arguments to the called pytest subprocess:
-s samples/subsys/testsuite/pytest/shell/sample.pytest.shell \ -s samples/subsys/testsuite/pytest/shell/sample.pytest.shell \
--pytest-args='-k test_shell_print_version' --pytest-args='-k test_shell_print_version'
The command line arguments will extend those from the .yaml file. If the same argument is
present in both places, the one from the command line will take precedence.
Fixtures Fixtures
******** ********

View file

@ -234,7 +234,7 @@ Artificially long but functional example:
parser.add_argument( parser.add_argument(
"--pytest-args", action="append", "--pytest-args", action="append",
help="""Pass additional arguments to the pytest subprocess. This parameter help="""Pass additional arguments to the pytest subprocess. This parameter
will override the pytest_args from the harness_config in YAML file. will extend the pytest_args from the harness_config in YAML file.
""") """)
valgrind_asan_group.add_argument( valgrind_asan_group.add_argument(

View file

@ -421,12 +421,8 @@ class Pytest(Harness):
if handler.options.pytest_args: if handler.options.pytest_args:
command.extend(handler.options.pytest_args) command.extend(handler.options.pytest_args)
if pytest_args_yaml:
logger.warning(f'The pytest_args ({handler.options.pytest_args}) specified ' command.extend(pytest_args_yaml)
'in the command line will override the pytest_args defined '
f'in the YAML file {pytest_args_yaml}')
else:
command.extend(pytest_args_yaml)
return command return command

View file

@ -74,7 +74,7 @@ def test_pytest_command_extra_args(testinstance: TestInstance):
def test_pytest_command_extra_args_in_options(testinstance: TestInstance): def test_pytest_command_extra_args_in_options(testinstance: TestInstance):
pytest_harness = Pytest() pytest_harness = Pytest()
pytest_args_from_yaml = '-k test_from_yaml' pytest_args_from_yaml = '--extra-option'
pytest_args_from_cmd = ['-k', 'test_from_cmd'] pytest_args_from_cmd = ['-k', 'test_from_cmd']
testinstance.testsuite.harness_config['pytest_args'] = [pytest_args_from_yaml] testinstance.testsuite.harness_config['pytest_args'] = [pytest_args_from_yaml]
testinstance.handler.options.pytest_args = pytest_args_from_cmd testinstance.handler.options.pytest_args = pytest_args_from_cmd
@ -82,7 +82,7 @@ def test_pytest_command_extra_args_in_options(testinstance: TestInstance):
command = pytest_harness.generate_command() command = pytest_harness.generate_command()
assert pytest_args_from_cmd[0] in command assert pytest_args_from_cmd[0] in command
assert pytest_args_from_cmd[1] in command assert pytest_args_from_cmd[1] in command
assert pytest_args_from_yaml not in command assert pytest_args_from_yaml in command
@pytest.mark.parametrize( @pytest.mark.parametrize(