1# Copyright (c) 2020 Intel Corporation.
2#
3# SPDX-License-Identifier: Apache-2.0
4
5import os
6import pytest
7
8# fixture cmdopt defined in conftest.py, it can be requested either in
9# tests or in other fixtures
10
11@pytest.fixture(autouse=True)
12def pytest_cmdopt_handle(cmdopt):
13    ''' An auto fixture, all tests automatically request this fixture.
14        Argument "cmdopt" is a fixture defined in conftest.py, it returns
15        the value of an option passed by twister, this fixture export
16        that value to environment.
17    '''
18    print("handle cmdopt:")
19    print(cmdopt)
20    data_path = cmdopt
21    os.environ['data_path'] = str(data_path)
22
23def test_case(cmdopt):
24    ''' Test cases make use of fixture cmdopt to get the value of "--cmdopt" option
25        passed by twister. Actually, fixture cmdopt returns a path of the directory
26        which holds the artifacts generated by ztest. The main work of test cases
27        in this file is to check those stuff in that directory.
28        This test case simply compare the return value of cmdopt with the
29        environment variable exported by fixture pytest_cmdopt_handle.
30    '''
31    assert os.path.exists(cmdopt)
32
33    print("run test cases in:")
34    print(cmdopt)
35
36def test_custom_arg(custom_pytest_arg):
37    ''' Test passing of custom command line arguments to pytest.
38    '''
39    assert custom_pytest_arg == "foo"
40
41if __name__ == "__main__":
42    pytest.main()
43