Skip to content

Commit

Permalink
samples: subsys: testsuite: pytest: add test of custom cmd line args
Browse files Browse the repository at this point in the history
Add test case for passing custom command line arguments to a pytest
harness via twister.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
  • Loading branch information
henrikbrixandersen authored and nashif committed Feb 28, 2022
1 parent 7249dab commit 8386e1f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions samples/subsys/testsuite/pytest/pytest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ def pytest_addoption(parser):
parser.addoption(
'--cmdopt'
)
parser.addoption(
'--custom-pytest-arg'
)

# define fixture to return value of option "--cmdopt", this fixture
# will be requested by other fixture of tests.
@pytest.fixture()
def cmdopt(request):
return request.config.getoption('--cmdopt')

# define fixture to return value of option "--custom-pytest-arg", this fixture
# will be requested by other fixture of tests.
@pytest.fixture()
def custom_pytest_arg(request):
return request.config.getoption('--custom-pytest-arg')
5 changes: 5 additions & 0 deletions samples/subsys/testsuite/pytest/pytest/test_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@ def test_case(cmdopt):
print("run test cases in:")
print(cmdopt)

def test_custom_arg(custom_pytest_arg):
''' Test passing of custom command line arguments to pytest.
'''
assert custom_pytest_arg == "foo"

if __name__ == "__main__":
pytest.main()
2 changes: 2 additions & 0 deletions samples/subsys/testsuite/pytest/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ tests:
sample.twister.pytest:
platform_allow: native_posix
harness: pytest
harness_config:
pytest_args: [ "--custom-pytest-arg", "foo" ]
tags: testing pytest

0 comments on commit 8386e1f

Please sign in to comment.