In this lesson, you will learn:

  • The key differences between Pytest and Unittest.

You can find the scripts and code for this lesson within the Pytest repo under the directory: 002_getting_started/003_pytest_vs_unittest.

Another Python testing framework is Unittest. You may now be asking, why use Pytest over Unittest? Well, the simple answer to this is simplicity! Let me explain why.

Unittest vs Pytest

To learn why Pytest is considered easier and simpler to work with, let’s look at 2 simple test functions written in both Pytest and Unittest (shown below). These examples highlight 2 main reasons why this is the case:


import unittest

class ClassTest(unittest.TestCase):

     def test_hello_world_1(self):
        self.assertEqual(1, 1)

     def test_hello_world_2(self):
        self.c(1, 2)


def test_hello_world_1():
    assert 1 == 1

def test_hello_world_2():
    assert 1 <= 2
Members Only Content
Want to Learn Network Automation?
Join our membership to access:
  • 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
  • Tech demos and sessions

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.