diff --git a/testimony/__init__.py b/testimony/__init__.py index 2561809..afd6240 100755 --- a/testimony/__init__.py +++ b/testimony/__init__.py @@ -292,23 +292,38 @@ def print_report(testcases): :param testcases: A dict where the key is a path and value is a list of found testcases on that path. """ - result = {} - for path, tests in testcases.items(): - result[path] = [test.to_dict() for test in tests] - if not SETTINGS['json']: - print('{0}\n{1}\n'.format( - colored(path, attrs=['bold']), '=' * len(path))) - if len(tests) == 0: - print('No test cases found.\n') + if SETTINGS['json']: + result = [] + for path, tests in testcases.items(): for test in tests: - title = testcase_title(test) - print('{0}\n{1}\n\n{2}\n'.format( - title, '-' * len(title), test)) + test_dict = test.to_dict() + test_data = test_dict['tokens'] + testimony_metadata = {} + testimony_metadata['file-path'] = path + testimony_metadata['test-class'] = test.parent_class + testimony_metadata['test-name'] = test.name + testimony_metadata['invalid-tokens'] = test_dict[ + 'invalid-tokens'] + testimony_metadata['rst-parse-messages'] = test_dict[ + 'rst-parse-messages'] + test_data['_testimony'] = testimony_metadata + result.append(test_data) - if SETTINGS['json']: print(json.dumps(result)) return 0 + result = {} + for path, tests in testcases.items(): + result[path] = [test.to_dict() for test in tests] + print('{0}\n{1}\n'.format( + colored(path, attrs=['bold']), '=' * len(path))) + if len(tests) == 0: + print('No test cases found.\n') + for test in tests: + title = testcase_title(test) + print('{0}\n{1}\n\n{2}\n'.format( + title, '-' * len(title), test)) + def summary_report(testcases): """Summary about the test cases report."""