Skip to content

Commit ec883ee

Browse files
committed
Code cleanup.
1 parent 436a409 commit ec883ee

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

pytest_dependency.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ class DependencyManager(object):
4747
"""Dependency manager, stores the results of tests.
4848
"""
4949

50-
ScopeCls = {'class':pytest.Class, 'module':pytest.Module, 'session':pytest.Session}
50+
ScopeCls = {
51+
'session': pytest.Session,
52+
'module': pytest.Module,
53+
'class': pytest.Class,
54+
}
5155

5256
@classmethod
5357
def getManager(cls, item, scope='module'):
@@ -67,12 +71,16 @@ def __init__(self, scope):
6771

6872
def addResult(self, item, name, rep):
6973
if not name:
70-
if self.scope == "session":
71-
name = item.nodeid.replace("::()::", "::")
72-
elif item.cls and self.scope == "module":
73-
name = "%s::%s" % (item.cls.__name__, item.name)
74+
nodeid = item.nodeid.replace("::()::", "::")
75+
if self.scope == 'session' or self.scope == 'package':
76+
name = nodeid
77+
elif self.scope == 'module':
78+
name = nodeid.split("::", maxsplit=1)[1]
79+
elif self.scope == 'class':
80+
name = nodeid.split("::", maxsplit=2)[2]
7481
else:
75-
name = item.name
82+
raise RuntimeError("Internal error: invalid scope '%s'"
83+
% self.scope)
7684
status = self.results.setdefault(name, DependencyItemStatus())
7785
status.addResult(rep)
7886

@@ -144,10 +152,9 @@ def pytest_runtest_makereport(item, call):
144152
if marker is not None or _automark:
145153
rep = outcome.get_result()
146154
name = marker.kwargs.get('name') if marker is not None else None
147-
""" Store the test outcome for each scope if it exists"""
148155
for scope in DependencyManager.ScopeCls:
149156
manager = DependencyManager.getManager(item, scope=scope)
150-
if(manager):
157+
if (manager):
151158
manager.addResult(item, name, rep)
152159

153160

@@ -159,6 +166,6 @@ def pytest_runtest_setup(item):
159166
if marker is not None:
160167
depends = marker.kwargs.get('depends')
161168
if depends:
162-
scope = marker.kwargs.get('scope', 'module') if marker is not None else 'module'
169+
scope = marker.kwargs.get('scope', 'module')
163170
manager = DependencyManager.getManager(item, scope=scope)
164171
manager.checkDepend(depends, item)

0 commit comments

Comments
 (0)