In this lesson, you will learn:

  • How to populate your fixture data via the CLI.

You can find the scripts and code for this lesson within the Pytest repo under the directory: 003_fixtures/005_fixture_cli.


So far within this course, we have seen examples where we have statically set fixture data and also pulled fixture data from the network. Another mechanism for passing fixture data into Pytest is via the CLI.

Customizing the Pytest CLI

For example, based on our previous examples, let's say we wanted to pass in the expected VLAN via the CLI (shown below) using the --vlan input. \

pytest -v . --vlan 100 --tb=no 

Let’s step through how this is done, all of which is performed within the file:

  1. First, we perform the required import of a new decorator (fixture).
  2. We then add a function name pytest_addoption and add in the new CLI option.
  3. We then create a fixture using the fixture decorator.
  4. The name of this fixture (in our case expected_vlan) can then be passed to our test function.
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.