Skip to content

Commit

Permalink
Update testcase title output
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
elyezer committed Apr 6, 2017
1 parent 8be54d4 commit 94b2cae
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 68 deletions.
92 changes: 54 additions & 38 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
++++++++++++
Expand Down
22 changes: 20 additions & 2 deletions testimony/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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']:
Expand Down
56 changes: 28 additions & 28 deletions tests/sample_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
tests/test_sample.py
====================

test_outside_class
------------------
test_outside_class:8
--------------------

Assert:
Testimony works with test functions
Expand All @@ -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
Expand All @@ -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
Expand All @@ -73,8 +73,8 @@ Test:
Login with Latin credentials


test_positive_login_4
---------------------
Testsample1::test_positive_login_4:71
-------------------------------------

Assert:
Activation key is created
Expand All @@ -96,8 +96,8 @@ Test:
Login with Credentials having special characters


test_negative_login_5
---------------------
Testsample1::test_negative_login_5:87
-------------------------------------

Bz:
123456
Expand All @@ -118,8 +118,8 @@ Test:
Test missing required docstrings


test_negative_login_6
---------------------
Testsample2::test_negative_login_6:107
--------------------------------------

Assert:
Login failed
Expand Down Expand Up @@ -149,8 +149,8 @@ Type:
Functional


test_negative_login_7
---------------------
Testsample3::test_negative_login_7:133
--------------------------------------

Assert:
Login failed
Expand All @@ -169,8 +169,8 @@ Test:
Login with invalid credentials


test_invalid_list_style
-----------------------
RSTFormattingTestCase::test_invalid_list_style:150
--------------------------------------------------

RST parser messages:

Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:

Expand Down

0 comments on commit 94b2cae

Please sign in to comment.