This lesson is part of the Network Testing with Pytest course.
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