I would like to generate parameters for a test
def test_project_run(prj_root, board_type, successful_output, test_input)
using the pytest framework.
I want the parameters to be based on data in a YAML file with all needed information
Zephyr:
projects:
- prj_root: "/home/ubuntu/nrf5340_threads"
prj_name: "threads"
test_input: []
successful_output: ["Toggled led0:", "Toggled led1:"]
boards_to_test_on: ["nrf5340", "mps2-an521"]
- prj_root: "/home/ubuntu/nrf5340_psa"
prj_name: "psa"
test_input: ["run"]
successful_output: ["encrypted"]
boards_to_test_on: ["nrf5340", "mps2-an521" ]
From all this parameters I would like to create a costum ID from prj_name
and board_to_test_on
. So I would be able to use the -k
option to run a specific test.
2
Answers
Do you mean custom ID?
I wrote a library called Parametrize From File that aims to make it easy to load test parameters from structured data files. Here’s what basic usage looks like:
Hopefully you can see how the values in the YAML file correspond directly to the parameters of the test function. In your case, there are two additional complexities to consider:
The key to both of these features is providing the
pff.parametrize(preprocess=...)
argument, which allow you to perform arbitrary transformations on the test parameters before running the test. The snippet below shows exactly how to do this:I don’t understand the meaning of the "Zephyr/projects" keys, so I didn’t consider that in the example above. Parametrize From File assumes that the top level keys in the parameter file correspond to the names of the test functions (e.g.
test_project_run
in this case), but if necessary you can customize this using thepff.parametrize(loaders=...)
argument.