Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Simple test runner for python unit tests
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