Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from unittest import TestLoader, TextTestRunner
def discover_and_run(verbose=False, names=None):
# names is None or a list [name, ...]
# name is test_suite[.class[.name]]
verbosity = 2 if verbose else 1
loader = TestLoader()
if names:
tests = loader.loadTestsFromNames(names)
tests ='test', '*.py', '..')
testRunner = TextTestRunner(verbosity=verbosity)
run_result =
# Report to shell the exit status
exit(0 if run_result.wasSuccessful() else 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment