Skip to content

Instantly share code, notes, and snippets.

Embed
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)
else:
tests = loader.discover('test', '*.py', '..')
testRunner = TextTestRunner(verbosity=verbosity)
run_result = testRunner.run(tests)
# 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