This lesson is part of the Network Testing with Pytest course.
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.
Introduction
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 conftest.py
file:
- First, we perform the required import of a new decorator (
fixture
). - We then add a function name
pytest_addoption
and add in the new CLI option. - We then create a fixture using the
fixture
decorator. - The name of this fixture (in our case
expected_vlan
) can then be passed to our test function.