The other day I was asked,
With the huge amount of tools and frameworks available to us now for network automation, I thought this was a great question and something I thought I would quickly answer in this post today.
So first of all ...
What is Pytest?
Pytest is a Python testing framework. It allows you to write tests in Python, using the Python
assert keyword, to validate a condition is
True. Like so:
def test_vlan(): device_vlan = "100" expected_vlan = "101" assert device_vlan == expected_vlan
Pytest provides a CLI, run-time, and build test framework. Therefore, we will still need to add whatever other tools we need to collect information from the network, parse the data, etc. Below is an example Pytest stack:
- To output reports within Pytest, a plugin is required.
- To collect the data Netmiko is required.
- To parse the data with Netmiko, we need to install the required parsing library (Genie, TextFSM, TTP etc.).
What is pyATS?
Whereas Pytest provides the testing framework and test execution. pyATS is a full-blown (also Python-based) testing framework that includes:
- Various libraries for performing differentials (Genie Diff) and abstracting the commands you need to run (Genie Learn).
- Testing runtime and execution (AETest and Easypy)
- Testing addons such as HTML reports etc.
- Libraries for connecting to devices (Unicon).
Below is an example...
When to Use What?
pyATS is great, and you can get some super quick wins. But with it being a full framework, it can become tricky to do things outside of what the framework provides. For example, let's say you wanted to use Scrapli to connect to the devices or use parsers from a library outside of the Genie parsers such as TextFSM.
This is where Pytest is great as it allows you to completely decouple your testing stack. Yes, you may not have everything there out of the box and need to create a little more boilerplate code in places, but with this you get flexibility.
If you want to learn more about Pytest or pyATS check out our courses below: