In this lesson, you will learn:

  • Why do we need Pytest?
  • What is Pytest?

Network Testing

Over the years we have seen a lot of focus on the use of tools such as Ansible and Nornir for network configuration management. Which is great. But to ensure these changes are safe and non-disruptive to our network, we also need a way to automate the testing and validation of our network - both in terms of validating that our configuration is valid and ok to be applied to the network (pre-testing) and in terms of validating that our network is running as expected once the configuration has been applied (post-testing).

Today there are a plethora of tools available to us for network automation, be it it CLI scraping tools such as Scrapli or Netmiko, network modelling tools for pre-testing such as Batfish, or network observability tools (for post-testing) such as Suzieq.

The question now is:

How can we build and execute tests against our network, using these tools in a structured, flexible and pragmatic way?

I mean, do we really need to write a myriad of if-else conditional statement scripts around all the various settings and states that should be present in the network?

I'm happy to say that the answer to this is no! Now, let me introduce you to Pytest.

Pytest

Pytest is a flexible, mature and feature-rich framework for testing Python code. The key strength of Pytest is its simplicity. This simplicity can be boiled down to:

tests are easy to write and read.

Pytest provides an easy-to-use CLI which initiates your test run. This results in your tests being automatically discovered and run, and the test results being displayed in an easy-to-view format. Because of this, Pytest is great not only for traditional Python code testing, but also for network testing. In other words, Pytest is the perfect framework for leveraging the various network automation tools and network data available to us, in order for us to test and validate the network.

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 ➜