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.

Ready to Master Network Automation? Start Your Journey Today!
Our membership provides:
  • Full deep-dive course library (inc. Batfish, pyATS, Netmiko)
  • Code repositories inc. full course code, scripts and examples
  • 24x7 multi-vendor labs (Arista, Cisco, Juniper)
  • Private online community
  • Live monthly tech sessions
  • Access to tech session library

Join Now ➜
Close You've successfully subscribed to Packet Coders.
Close Success! Your account is fully activated, you now have access to all content.
Close Welcome back! You've successfully signed in.
Close Nearly there! To activate your account, please click the link in the email we just sent you.