From 94b2cae257a17fe980ee186134b775c68c7f6642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ely=C3=A9zer=20Rezende?= Date: Thu, 6 Apr 2017 14:54:02 -0300 Subject: [PATCH] Update testcase title output Include the parent class (if available) and the line number when showing information about test cases. This helps users identify which exactly tests Testimony is presenting. --- docs/index.rst | 92 ++++++++++++++++++++++++----------------- testimony/__init__.py | 22 +++++++++- tests/sample_output.txt | 56 ++++++++++++------------- 3 files changed, 102 insertions(+), 68 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index ff37c2b..1d70d36 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -158,29 +158,30 @@ test. Also it prints non-recognized tokens. tests/test_sample.py ==================== - test_positive_login_1 - --------------------- + test_outside_class:8 + -------------------- Assert: - Login is successful + Testimony works with test functions + + Feature: + Test functions Setup: - Setup Testsample1 + Global setup - Steps: - 1. Login to the application with valid credentials + Test: + Test testimony works with test functions. - Tags: - t1, t2, t3 - Test: - Login with right credentials + Testsample1::test_positive_login_1:27 + ------------------------------------- - Unexpected tokens: - Bug: 123456 - Feture: Login - Positive - Statues: Manual - Types: Functional + Assert: + Login is successful + + Setup: + Setup Testsample1 .. note:: The print command above uses the ``head`` command to show just one test @@ -235,37 +236,52 @@ For example: .. code-block:: console - $ testimony validate tests/ + $ testimony validate tests/ + + tests/test_sample.py + ==================== + + Testsample1::test_positive_login_1:27 + ------------------------------------- + + * Docstring should have at least assert, feature, test token(s) + * Unexpected tokens: + Bug: 123456 + Feture: Login - Positive + Statues: Manual + Types: Functional + + Testsample1::test_positive_login_2:49 + ------------------------------------- + + * Missing docstring. + * Docstring should have at least assert, feature, test token(s) + + Testsample1::test_negative_login_5:87 + ------------------------------------- - tests/test_sample.py - ==================== + * Docstring should have at least assert, feature, test token(s) - test_positive_login_1 - --------------------- + RSTFormattingTestCase::test_invalid_list_style:150 + -------------------------------------------------- - * Docstring should have at least assert, feature, test token(s) - * Unexpected tokens: - Bug: 123456 - Feture: Login - Positive - Statues: Manual - Types: Functional + * Docstring has RST parsing issues. RST parser messages: - test_positive_login_2 - --------------------- + * Enumerated list ends without a blank line; unexpected unindent. - * Missing docstring. - * Docstring should have at least assert, feature, test token(s) + :Steps: + 1. Have a RST list on any of the tokens, like steps. + > 2. Make sure one of the items on the list goes across multiple + lines and the lines are not properly indented. - test_negative_login_5 - --------------------- - * Docstring should have at least assert, feature, test token(s) - Total number of tests: 7 - Total number of invalid docstrings: 3 (42.86%) - Test cases with no docstrings: 1 (14.29%) - Test cases missing minimal docstrings: 3 (42.86%) - Test cases with invalid tags: 1 (14.29%) + Total number of tests: 10 + Total number of invalid docstrings: 4 (40.00%) + Test cases with no docstrings: 1 (10.00%) + Test cases missing minimal docstrings: 3 (30.00%) + Test cases with invalid tags: 1 (10.00%) + Total number of tests with parsing issues: 1 (10.00%) Misc Options ++++++++++++ diff --git a/testimony/__init__.py b/testimony/__init__.py index 904bc91..391d062 100755 --- a/testimony/__init__.py +++ b/testimony/__init__.py @@ -66,6 +66,22 @@ def is_test_module(filename): return False +def testcase_title(testcase): + """Generate a title using testcase information. + + The generated title will be in the format: + + [ParentClass::]test_name:line_number + + The ParentClass will be present only if the test is withing a class. + """ + return '{0}{1}:{2}'.format( + testcase.parent_class + '::' if testcase.parent_class else '', + testcase.name, + testcase.function_def.lineno, + ) + + class TestFunction(object): """Wrapper for ``ast.FunctionDef`` which parse docstring information. @@ -254,8 +270,9 @@ def print_report(testcases): 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( - test.name, '-' * len(test.name), test)) + title, '-' * len(title), test)) if SETTINGS['json']: print(json.dumps(result)) @@ -357,8 +374,9 @@ def validate_docstring_report(testcases): )) invalid_tags_docstring_count += 1 if issues: + title = testcase_title(testcase) result.setdefault( - path, collections.OrderedDict())[testcase.name] = issues + path, collections.OrderedDict())[title] = issues invalid_docstring_count += 1 if SETTINGS['json']: diff --git a/tests/sample_output.txt b/tests/sample_output.txt index 5dca53c..5ec3c39 100644 --- a/tests/sample_output.txt +++ b/tests/sample_output.txt @@ -5,8 +5,8 @@ tests/test_sample.py ==================== -test_outside_class ------------------- +test_outside_class:8 +-------------------- Assert: Testimony works with test functions @@ -21,8 +21,8 @@ Test: Test testimony works with test functions. -test_positive_login_1 ---------------------- +Testsample1::test_positive_login_1:27 +------------------------------------- Assert: Login is successful @@ -46,13 +46,13 @@ Unexpected tokens: Statues: Manual Types: Functional -test_positive_login_2 ---------------------- +Testsample1::test_positive_login_2:49 +------------------------------------- -test_positive_login_3 ---------------------- +Testsample1::test_positive_login_3:54 +------------------------------------- Assert: Login is successful @@ -73,8 +73,8 @@ Test: Login with Latin credentials -test_positive_login_4 ---------------------- +Testsample1::test_positive_login_4:71 +------------------------------------- Assert: Activation key is created @@ -96,8 +96,8 @@ Test: Login with Credentials having special characters -test_negative_login_5 ---------------------- +Testsample1::test_negative_login_5:87 +------------------------------------- Bz: 123456 @@ -118,8 +118,8 @@ Test: Test missing required docstrings -test_negative_login_6 ---------------------- +Testsample2::test_negative_login_6:107 +-------------------------------------- Assert: Login failed @@ -149,8 +149,8 @@ Type: Functional -test_negative_login_7 ---------------------- +Testsample3::test_negative_login_7:133 +-------------------------------------- Assert: Login failed @@ -169,8 +169,8 @@ Test: Login with invalid credentials -test_invalid_list_style ------------------------ +RSTFormattingTestCase::test_invalid_list_style:150 +-------------------------------------------------- RST parser messages: @@ -186,8 +186,8 @@ RST parser messages: tests/sample_pkg/test_sample2.py ================================ -test_positive_login_3 ---------------------- +TestPackage1::test_positive_login_3:15 +-------------------------------------- Assert: Login is successful @@ -232,8 +232,8 @@ Type: 1 (10.00%) tests/test_sample.py ==================== -test_positive_login_1 ---------------------- +Testsample1::test_positive_login_1:27 +------------------------------------- * Docstring should have at least assert, feature, test token(s) * Unexpected tokens: @@ -242,19 +242,19 @@ test_positive_login_1 Statues: Manual Types: Functional -test_positive_login_2 ---------------------- +Testsample1::test_positive_login_2:49 +------------------------------------- * Missing docstring. * Docstring should have at least assert, feature, test token(s) -test_negative_login_5 ---------------------- +Testsample1::test_negative_login_5:87 +------------------------------------- * Docstring should have at least assert, feature, test token(s) -test_invalid_list_style ------------------------ +RSTFormattingTestCase::test_invalid_list_style:150 +-------------------------------------------------- * Docstring has RST parsing issues. RST parser messages: