diff --git a/tests/pytest/pytest_sample/CMakeLists.txt b/tests/pytest/pytest_sample/CMakeLists.txt new file mode 100644 index 00000000000000..ed70dc5e6cf4f1 --- /dev/null +++ b/tests/pytest/pytest_sample/CMakeLists.txt @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(pytest_sample) + +target_sources(app PRIVATE src/main.c) diff --git a/tests/pytest/pytest_sample/prj.conf b/tests/pytest/pytest_sample/prj.conf new file mode 100644 index 00000000000000..c3e81438cedda9 --- /dev/null +++ b/tests/pytest/pytest_sample/prj.conf @@ -0,0 +1,2 @@ +CONFIG_ZTEST=y +CONFIG_IDLE_STACK_SIZE=4096 diff --git a/tests/pytest/pytest_sample/pytest/conftest.py b/tests/pytest/pytest_sample/pytest/conftest.py new file mode 100644 index 00000000000000..71104c2d5ab12b --- /dev/null +++ b/tests/pytest/pytest_sample/pytest/conftest.py @@ -0,0 +1,14 @@ +# Copyright (c) 2020 Intel Corporation. +# +# SPDX-License-Identifier: Apache-2.0 + +import pytest + +def pytest_addoption(parser): + parser.addoption( + '--cmdopt' + ) + +@pytest.fixture() +def cmdopt(request): + return request.config.getoption('--cmdopt') diff --git a/tests/pytest/pytest_sample/pytest/test_ctf.py b/tests/pytest/pytest_sample/pytest/test_ctf.py new file mode 100755 index 00000000000000..78d97c731b027b --- /dev/null +++ b/tests/pytest/pytest_sample/pytest/test_ctf.py @@ -0,0 +1,24 @@ +# Copyright (c) 2020 Intel Corporation. +# +# SPDX-License-Identifier: Apache-2.0 + +import os +import pytest + +@pytest.fixture(autouse=True) +def pytest_cmdopt_handle(cmdopt): + ''' handle cmdopt ''' + print("handle cmdopt:") + print(cmdopt) + data_path = cmdopt + os.environ['data_path'] = str(data_path) + +def test_case(cmdopt): + ''' test case ''' + if not os.path.exists(cmdopt): + assert 0 + print("run test cases in:") + print(cmdopt) + +if __name__ == "__main__": + pytest.main() diff --git a/tests/pytest/pytest_sample/src/main.c b/tests/pytest/pytest_sample/src/main.c new file mode 100644 index 00000000000000..dfb6085e9c6d4d --- /dev/null +++ b/tests/pytest/pytest_sample/src/main.c @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2020 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +void test_pytest(void) +{ + TC_PRINT("Hello world\n"); +} + +void test_main(void) +{ + ztest_test_suite(test_pytest, + ztest_unit_test(test_pytest) + ); + + ztest_run_test_suite(test_pytest); +} diff --git a/tests/pytest/pytest_sample/testcase.yaml b/tests/pytest/pytest_sample/testcase.yaml new file mode 100644 index 00000000000000..70731764e8561d --- /dev/null +++ b/tests/pytest/pytest_sample/testcase.yaml @@ -0,0 +1,4 @@ +tests: + pytest.sample: + platform_allow: qemu_x86 qemu_x86_64 + harness: pytest