Created
February 8, 2013 18:41
-
-
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.
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
# 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) |
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
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