The Python standard library unittest is a simple compact unit testing library that you can use out of the box. A very common way of running the test cases is using the discover feature of the command line tool invoked by python3 -m unittest which will discover and run all the test cases in folder / package. But if you want to do some logging, reporting before or after the test cases are run? The initial solution would be use the shell to chain those commands, e.g. python3 -m unittest | alertme.sh, which could be very cumbersome. Instead, we can replicate that functionality in Python and have more control over what happens:

import unittest

def discover_and_run(start_dir: str = '.', pattern: str = 'test*.py'):
    """Discover and run tests cases, returning the result."""
    tests = unittest.defaultTestLoader(start_dir, pattern=pattern)
    # We'll use the standard text runner which prints to stdout
    runner = unittest.TextTestRunner()
    result = runner.run(tests) # Returns a TestResult
    print(result.errors, result.failures) # And more useful properties
    return result

which uses the TestLoader.discover to find all the test cases and run them. Note that this is similar to what the command line version does as well, you can check the source code of the unittest library. The returned object is a TestResult which contains all the useful information. For example, now you can send an alert if a certain number of test cases failed.