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

Use from_parent #8

Merged
Merged
Changes from 1 commit
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
19 changes: 16 additions & 3 deletions pytest_mccabe.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,13 @@ def pytest_collect_file(path, parent):
if config.option.mccabe and path.ext == '.py':
complexity = config._mccabe_complexities(path)
if complexity != 0:
return McCabeItem(path, parent, complexity)
if hasattr(McCabeItem, "from_parent"):
MartinThoma marked this conversation as resolved.
Show resolved Hide resolved
item = McCabeItem.from_parent(parent,
fspath=path,
complexity=complexity)
return item
else:
return McCabeItem(path, parent, complexity)
return None


Expand All @@ -57,15 +63,22 @@ class McCabeError(Exception):

class McCabeItem(pytest.Item, pytest.File):

def __init__(self, path, parent, complexity):
super(McCabeItem, self).__init__(path, parent)
def __init__(self, fspath, parent, complexity):
super(McCabeItem, self).__init__(fspath, parent)
self._mtime = None
if hasattr(self, 'add_marker'):
self.add_marker("mccabe")
else:
self.keywords["mccabe"] = True
self.complexity = complexity

@classmethod
def from_parent(cls, parent, fspath, **kwargs):
MartinThoma marked this conversation as resolved.
Show resolved Hide resolved
complexity = kwargs.pop('complexity')
_self = getattr(super(), 'from_parent', cls)(parent, complexity=complexity, fspath=fspath)
_self.setup()
return _self

def setup(self):
mtimes = self.config._mccabe_mtimes
self._mtime = self.fspath.mtime()
Expand Down