When pytest generates the name for parametrized tests, simple parameter
values (ints, strings) get used directly, but more complex values such
as dicts are not handled. This yields test names such as:
dfu[env__usb_dev_port0-env__dfu_config0]
dfu[env__usb_dev_port0-env__dfu_config1]
Add some code to extract a custom fixture ID from the fixture values, so
that we end up with meaningful names such as:
dfu[micro_b-emmc]
dfu[devport2-ram]
If the boardenv file doesn't define custom names, the code falls back to
the old algorithm.
Signed-off-by: Stephen Warren <swarren@nvidia.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
# ... otherwise, see if there's a key that contains a list of
# values to use instead.
vals = subconfig.get(fn + 's', [])
- metafunc.parametrize(fn, vals)
+ def fixture_id(index, val):
+ try:
+ return val["fixture_id"]
+ except:
+ return fn + str(index)
+ ids = [fixture_id(index, val) for (index, val) in enumerate(vals)]
+ metafunc.parametrize(fn, vals, ids=ids)
@pytest.fixture(scope='function')
def u_boot_console(request):
env__usb_dev_ports = (
{
+ "fixture_id": "micro_b",
"tgt_usb_ctlr": "0",
"host_usb_dev_node": "/dev/usbdev-p2371-2180",
# This parameter is optional /if/ you only have a single board
env__dfu_configs = (
# eMMC, partition 1
{
+ "fixture_id": "emmc",
"alt_info": "/dfu_test.bin ext4 0 1;/dfu_dummy.bin ext4 0 1",
"cmd_params": "mmc 0",
},
)
+
b) udev rules to set permissions on devices nodes, so that sudo is not
required. For example:
env__usb_dev_ports = (
{
+ "fixture_id": "micro_b",
"tgt_usb_ctlr": "0",
"host_ums_dev_node": "/dev/disk/by-path/pci-0000:00:14.0-usb-0:13:1.0-scsi-0:0:0:0",
},
env__block_devs = (
# eMMC; always present
{
+ "fixture_id": "emmc",
"type": "mmc",
"id": "0",
# The following two properties are optional.
},
# SD card; present since I plugged one in
{
+ "fixture_id": "sd",
"type": "mmc",
"id": "1"
},