Python's unittest module

In the previous example, we saw how we could use the assertEqual() method to compare the two values to return either True or False. Here is an example of the built-in unittest module to compare two values:

$ cat chapter13_4_unittest.py#!/usr/bin/env python3import unittestclass SimpleTest(unittest.TestCase):    def test(self):        one = 'a'        two = 'a'        self.assertEqual(one, two)

Using the python3 command-line interface, the unittest module can automatically discover the test cases in the script:

$ python3 -m unittest chapter13_4_unittest.py.----------------------------------------------------------------------Ran 1 test in 0.000sOK

Besides comparing two values, here are more examples of testing if the expected value is

Get Mastering Python Networking - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.