In this lesson, you will learn:
- The key differences between Pytest and 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