Skip to content

Instantly share code, notes, and snippets.

@dhandeo
Created February 8, 2013 18:41
Show Gist options
  • Save dhandeo/4741027 to your computer and use it in GitHub Desktop.
Save dhandeo/4741027 to your computer and use it in GitHub Desktop.
Using python "unittest" with CTest CDash for testing web application written in "Flask". Some tests internally use browser automation using "selenium". Where the first line in the CTestTestfile uses another python function "list_tests.py" to discover all the unit tests starting current directory using unittest discover capability.
# Extract the test by running python code
execute_process(COMMAND "python" "list_tests.py" OUTPUT_VARIABLE STR_TESTS
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)
separate_arguments(TEST_LIST UNIX_COMMAND ${STR_TESTS})
foreach(ATEST ${TEST_LIST})
#message(" +")
#message(${ATEST})
add_test(${ATEST} "python" "-m" "unittest" "-v" ${ATEST})
endforeach(ATEST)
import unittest
DEBUG = False
def list_tests_from(path):
loader = unittest.TestLoader()
suite = loader.discover(path)
for atest in suite:
tests = atest._tests
if len(tests):
for atest in tests:
if DEBUG:
print atest
for btest in atest._tests:
btestname = btest.__str__().split()
print path + "." + btestname[1][1:-1] + "." + btestname[0]
if __name__ == "__main__":
# Include the directories
list_tests_from("unit")
list_tests_from("regression")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment