Skip to content

Solution of #213. Print test case detail with its status. #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions pyresttest/resttest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
import sys
import os
import inspect
Expand Down Expand Up @@ -622,6 +623,7 @@ def run_testsets(testsets):
""" Execute a set of tests, using given TestSet list input """
group_results = dict() # results, by group
group_failure_counts = dict()
group_test_case_results = dict()
total_failures = 0
myinteractive = False
curl_handle = pycurl.Curl()
Expand Down Expand Up @@ -652,6 +654,7 @@ def run_testsets(testsets):
# Initialize the dictionaries to store test fail counts and results
if test.group not in group_results:
group_results[test.group] = list()
group_test_case_results[test.group] = list()
group_failure_counts[test.group] = 0

result = run_test(test, test_config=myconfig, context=context, curl_handle=curl_handle)
Expand All @@ -661,6 +664,7 @@ def run_testsets(testsets):
# Use result test URL to allow for templating
logger.error('Test Failed: ' + test.name + " URL=" + result.test.url +
" Group=" + test.group + " HTTP Status Code: " + str(result.response_code))
status = 'FAILED'

# Print test failure reasons
if result.failures:
Expand All @@ -675,11 +679,13 @@ def run_testsets(testsets):
group_failure_counts[test.group] = failures

else: # Test passed, print results
status = 'Passed'
logger.info('Test Succeeded: ' + test.name +
" URL=" + test.url + " Group=" + test.group)
" URL=" + test.url + " Group=" + test.group)

# Add results for this test group to the resultset
group_results[test.group].append(result)
group_test_case_results[test.group].append({'test_case_name': test.name, 'status': status})

# handle stop_on_failure flag
if not result.passed and test.stop_on_failure is not None and test.stop_on_failure:
Expand Down Expand Up @@ -720,17 +726,27 @@ def run_testsets(testsets):
test_count = len(group_results[group])
failures = group_failure_counts[group]
total_failures = total_failures + failures
group_test_case = group_test_case_results[group]

passfail = {True: u'SUCCEEDED: ', False: u'FAILED: '}
output_string = "Test Group {0} {1}: {2}/{3} Tests Passed!".format(group, passfail[failures == 0], str(test_count - failures), str(test_count))

'''
Here is the string that you want to print on console
'''
output_string = "Cubii feature Name: {0} : {1}: {2}/{3} Tests Passed!".format(group, passfail[failures == 0], str(test_count - failures), str(test_count))

if myconfig.skip_term_colors:
print(output_string)
else:
if failures > 0:
print('\033[91m' + output_string + '\033[0m')
else:
print('\033[92m' + output_string + '\033[0m')
for single_test_case in group_test_case:
sub_test_case = "{0} -- {1}".format(single_test_case['test_case_name'],single_test_case['status'])
if single_test_case['status'] == 'Passed':
print('\033[90m' + sub_test_case + '\033[0m')
else:
print('\033[90m' + sub_test_case + '\033[0m')
Copy link

@j796160836 j796160836 Jul 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Support skip_term_colors options will be great.
  2. Change failed case color code to \033[92m will be great.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for enhance it


return total_failures

Expand Down Expand Up @@ -914,5 +930,5 @@ def command_line_run(args_in):
main(args)

# Allow import into another module without executing the main method
if(__name__ == '__main__'):
if __name__ == '__main__':
command_line_run(sys.argv[1:])