Skip to content

Commit

Permalink
Fix issue when parsing test functions
Browse files Browse the repository at this point in the history
Test functions don't have a parent class, fix the exception raised when
parsing test functions.

Close #132
  • Loading branch information
elyezer committed Mar 23, 2017
1 parent 5193107 commit 3c4beb7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
11 changes: 8 additions & 3 deletions testimony/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ def __init__(self, function_def, parent_class=None, testmodule=None):
self.docstring = ast.get_docstring(function_def)
self.function_def = function_def
self.name = function_def.name
self.parent_class = parent_class.name
self.parent_class_def = parent_class
self.class_docstring = ast.get_docstring(self.parent_class_def)
if parent_class:
self.parent_class = parent_class.name
self.parent_class_def = parent_class
self.class_docstring = ast.get_docstring(self.parent_class_def)
else:
self.parent_class = None
self.parent_class_def = None
self.class_docstring = None
self.testmodule = testmodule.path
self.module_def = testmodule
self.module_docstring = ast.get_docstring(self.module_def)
Expand Down
48 changes: 32 additions & 16 deletions tests/sample_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
tests/test_sample.py
====================

test_outside_class
------------------

Assert:
Testimony works with test functions

Feature:
Test functions

Setup:
Global setup

Test:
Test testimony works with test functions.


test_positive_login_1
---------------------

Expand Down Expand Up @@ -183,17 +199,17 @@ Test:
= summary report =
==================

Total number of tests: 8
Test cases with no docstrings: 1 (12.50%)
Assert: 6 (75.00%)
Bz: 2 (25.00%)
Feature: 5 (62.50%)
Setup: 7 (87.50%)
Status: 3 (37.50%)
Steps: 7 (87.50%)
Tags: 5 (62.50%)
Test: 7 (87.50%)
Type: 1 (12.50%)
Total number of tests: 9
Test cases with no docstrings: 1 (11.11%)
Assert: 7 (77.78%)
Bz: 2 (22.22%)
Feature: 6 (66.67%)
Setup: 8 (88.89%)
Status: 3 (33.33%)
Steps: 7 (77.78%)
Tags: 5 (55.56%)
Test: 8 (88.89%)
Type: 1 (11.11%)

=============================
= validate_docstring report =
Expand Down Expand Up @@ -223,8 +239,8 @@ test_negative_login_5

* Docstring should have at least assert, feature, test token(s)

Total number of tests: 8
Total number of invalid docstrings: 3 (37.50%)
Test cases with no docstrings: 1 (12.50%)
Test cases missing minimal docstrings: 3 (37.50%)
Test cases with invalid tags: 1 (12.50%)
Total number of tests: 9
Total number of invalid docstrings: 3 (33.33%)
Test cases with no docstrings: 1 (11.11%)
Test cases missing minimal docstrings: 3 (33.33%)
Test cases with invalid tags: 1 (11.11%)
9 changes: 9 additions & 0 deletions tests/test_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
"""


def test_outside_class():
"""Test testimony works with test functions.
:Feature: Test functions
:Assert: Testimony works with test functions
"""


class Testsample1():
"""This is a dummy test file used for testing testimony
Expand Down

0 comments on commit 3c4beb7

Please sign in to comment.