main: refactor a bit to reduce indentation

This commit is contained in:
Ran Benita 2020-08-21 14:19:14 +03:00
parent adaec2da90
commit a2c919d350
1 changed files with 28 additions and 32 deletions

View File

@ -748,38 +748,34 @@ class Session(nodes.FSCollector):
self.trace("matchnodes", matching, names) self.trace("matchnodes", matching, names)
self.trace.root.indent += 1 self.trace.root.indent += 1
if not names: result = []
result = matching for node in matching:
else: if not names:
name = names[0] result.append(node)
assert name continue
resultnodes = [] # type: List[Union[nodes.Item, nodes.Collector]] if not isinstance(node, nodes.Collector):
for node in matching: continue
if isinstance(node, nodes.Item): key = (type(node), node.nodeid)
continue if key in self._collection_node_cache3:
assert isinstance(node, nodes.Collector) rep = self._collection_node_cache3[key]
key = (type(node), node.nodeid) else:
if key in self._collection_node_cache3: rep = collect_one_node(node)
rep = self._collection_node_cache3[key] self._collection_node_cache3[key] = rep
else: if rep.passed:
rep = collect_one_node(node) has_matched = False
self._collection_node_cache3[key] = rep for x in rep.result:
if rep.passed: # TODO: Remove parametrized workaround once collection structure contains parametrization.
has_matched = False if x.name == names[0] or x.name.split("[")[0] == names[0]:
for x in rep.result: result.extend(self.matchnodes([x], names[1:]))
# TODO: Remove parametrized workaround once collection structure contains parametrization. has_matched = True
if x.name == name or x.name.split("[")[0] == name: # XXX Accept IDs that don't have "()" for class instances.
resultnodes.extend(self.matchnodes([x], names[1:])) if not has_matched and len(rep.result) == 1 and x.name == "()":
has_matched = True result.extend(self.matchnodes([x], names))
# XXX Accept IDs that don't have "()" for class instances. else:
if not has_matched and len(rep.result) == 1 and x.name == "()": # Report collection failures here to avoid failing to run some test
resultnodes.extend(self.matchnodes([x], names)) # specified in the command line because the module could not be
else: # imported (#134).
# Report collection failures here to avoid failing to run some test node.ihook.pytest_collectreport(report=rep)
# specified in the command line because the module could not be
# imported (#134).
node.ihook.pytest_collectreport(report=rep)
result = resultnodes
self.trace("matchnodes finished -> ", len(result), "nodes") self.trace("matchnodes finished -> ", len(result), "nodes")
self.trace.root.indent -= 1 self.trace.root.indent -= 1