Skip to content
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

[WIP] Classes nested in tests break following test method detection #12

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 17 additions & 3 deletions test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ class TestParser(ast.NodeVisitor):
>>> list(set(map(parser.parse, (21, 22))))
[(None, 'func_test')]

# nested classes are allowed
>>> list(set(map(parser.parse, (25, 26, 27, 28, 31))))
[('ParentClass', None)]
[('ParentClassA', None)]

>>> list(set(map(parser.parse, (29, 30))))
[('ParentClass', None)]
[('ParentClassA', None)]

>>> list(set(map(parser.parse, (32, 33))))
[('ParentClass', 'parent_method')]
[('ParentClassA', 'parent_method')]

# test decorated test case and decorated method
>>> list(set(map(parser.parse, range(41, 44))))
Expand All @@ -66,6 +67,19 @@ class TestParser(ast.NodeVisitor):
>>> parser = TestParser(source=module_source)
>>> parser.parse(line=2)
(None, 'test_first')

# classes defined in test are ignored
>>> list(set(map(parser.parse, (54, 55, 56))))
[('ParentClassB', None)]

>>> list(set(map(parser.parse, (57, 58))))
[('ParentClassB', 'test_foo')]

>>> list(set(map(parser.parse, (60, 61, 63, 67, 68, ))))
[('ParentClassB', 'test_a')]

>>> list(set(map(parser.parse, (70, 71))))
[('ParentClassB', 'test_b')]
"""
nested_class = None

Expand Down
24 changes: 23 additions & 1 deletion tests/_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def func_test():
pass


class ParentClass(AnotherClass):
class ParentClassA(AnotherClass):
class ChildClass:
nested_property = True

Expand All @@ -49,3 +49,25 @@ def test_me(self):
class ParentInModuleClass(mymodule.TestClass):
def test_me(self):
pass


class ParentClassB(TestClass):
foo = 1

def test_foo(self):
pass

def test_a(self):
class ChildClass(object):
nested_property = True

def child_method(self):
pass

another_attribute = 'foo'

cl = ChildClass()
assert cl.nested_property

def test_b(self):
pass