main: make matchnodes non-recursive

It's a little more sane this way.
This commit is contained in:
Ran Benita 2020-08-21 16:50:28 +03:00
parent 841521fedb
commit c2256189ae
1 changed files with 35 additions and 33 deletions

View File

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