Created
October 6, 2016 05:59
-
-
Save barahilia/a1d31615854de71254b7f2eccebd774b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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