Created
January 31, 2011 10:11
-
-
Save grrussel/803854 to your computer and use it in GitHub Desktop.
Simple test runner for python unit tests
This file contains 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
def test_function1(): | |
# Do some test code | |
# return True on Pass, False on Fail | |
return True | |
def test_function2_EXPECTED_FAIL(): | |
# Do some test (more) code | |
# return True on Pass, False on Fail | |
return False | |
def test_functionN(): | |
# Do some test (more) code | |
# return True on Pass, False on Fail | |
return False | |
# Build a list of test functions to run | |
# as test cases | |
tests = [ test_function1 | |
, test_function2_EXPECTED_FAIL | |
#, ... | |
, test_functionN | |
] | |
def main(): | |
failed = [] | |
# Invoke each test case in turn | |
for t in tests: | |
if not t(): | |
# Can check names of test functions | |
# to detect expected fails | |
if t.__name__.endswith("_EXPECTED_FAIL"): | |
continue | |
# Record fails for later report | |
failed.append(t.__name__) | |
# Can stop on 1st fail if desired | |
# return 1 | |
# Print the list of tests that failed, if any | |
for f in failed: | |
print "FAIL:",f | |
# Invoke the test runner | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment