Introduction to the unittest Framework in Python

    unittest is typically imported with:

    Test classes should extend TestCase, and contain at least one method starting with test_ . Test methods contain assertions.

    TestCase offers many assertion methods (assertEqual, assertAlmostEqual, assertTrue etc.).

    1. self.assertEqual(add(3, 4), 7)

    Typically, you will find main() called in a separate code block:

    You can run Python test files with unittest without calling main()

    Note: The name of the test module is spelled without .py

      The methods setUp() and tearDown() can be used to prepare testing and clean up afterwards.

      Importing test data in multiple packages

      When you have many tests distributed to sub-packages, you may want to share test data among them. There are two ways to do so:

      Either set the PYTHONPATH variable to the directory with your tests.