In this lesson, you will learn:
- What are parameter IDs?
- How parameter ID customisation is performed in Pytest.
You can find the scripts and code for this lesson within the Pytest repo under the directory: 004_parametrization/004_parametrization_ids.
What are Parameter IDs?
When we dynamically generate tests via parametrization, Pytest automatically generates an ID based on the supplied parameters.
We saw this earlier when we parameterized our test with a sequence of VLANs (shown below). Here you can see that the generated ID consists of the VLAN ID we provided in brackets.
...
004_paramization/002_test_parametrization/pytest_example/test_001_vlan_pytest.py::test_vlan[100] FAILED
004_paramization/002_test_parametrization/pytest_example/test_001_vlan_pytest.py::test_vlan[101] FAILED
004_paramization/002_test_parametrization/pytest_example/test_001_vlan_pytest.py::test_vlan[102] FAILED
...
However, what about if we want to add some custom text or format this parameter ID in a certain way. Or let’s say it is not just a string we are passing in as a parameter but a dictionary containing the data we want to test. We wouldn't want to display the whole dictionary as an ID for each test. Based on these examples, this is where we would want to customize our parameter IDs, as we will now show.