1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
obj = module.MyClass() # MyClass contient les methodes qu'on peut exécuter (function_name)
function_name = 'function_1' #nom de la methode a ecéxuté
tests_function_1=[]
tests_function_1.append([function_name, (parm1, parm2)])
function_name = 'function_2'
tests_function_2=[]
tests_function_2.append([function_name, (parm8, parm9)])
tests_all = [] \
+ tests_function_1 \
+ tests_function_2 \
+ []
def run(tests = tests_all):
pass_count = 0
fail_count = 0
rest_count = len(tests)
for test_item in tests:
print '-' * 60
f_name, f_args = test_item
## Get the function object
func = getattr(obj, f_name, None)
# Check if function exists
if not func:
log.error("ERROR: test function '%s' doesn't exist" % f_name)
continue
# Run the test
try:
log.info("RUNNING: test function '%s%s'" % (f_name, str(f_args)))
rest_count = rest_count - 1
## Call the test function
if not f_args:
func() ## No arguments
else:
func(*f_args) ## Many arguments
pass_count = pass_count + 1
except KeyboardInterrupt:
break
except:
# An error occured
log.warn("WARNING: test function '%s' failed" % f_name)
fail_count = fail_count + 1
log.info('=' * 60)
log.info("Results: ran %d tests, %d pass, %d fail, %d remaining" %
(len(tests), pass_count, fail_count, rest_count))
log.info('=' * 60)
def main():
run() |
Partager