A very common technique for running unit tests — include a small piece of code (as shown in the code below) at the bottom of the test file.
Code # 1:
This makes the test executable and prints the test execution results to standard output. To redirect this output, unwind the main () call a bit and write your own main () function as shown in the code below:
Code # 2:
How it works:
unittest.TestLoaderinstance created in the solution is used to build the test suite.
loadTestsFromModule ()is one of several methods it defines for collecting tests … In this case, it scans the module for TestCase classes and extracts test methods from them.
loadTestsFromTestCase ()method (not shown) can be used to extract test methods from a separate class, which inherits from TestCase.
TextTestRunnerclass is an example of a test runner class. The main purpose of this class is — run the tests contained in the test suite. This class — the same test runner that sits behind the