main: inline Session._matchnodes() into Session.matchnodes()
Similar to the previous commit, this makes things more straightforward.
This commit is contained in:
parent
d121d7c917
commit
32edc4655c
|
@ -709,52 +709,51 @@ class Session(nodes.FSCollector):
|
||||||
) -> Sequence[Union[nodes.Item, nodes.Collector]]:
|
) -> Sequence[Union[nodes.Item, nodes.Collector]]:
|
||||||
self.trace("matchnodes", matching, names)
|
self.trace("matchnodes", matching, names)
|
||||||
self.trace.root.indent += 1
|
self.trace.root.indent += 1
|
||||||
nodes = self._matchnodes(matching, names)
|
|
||||||
num = len(nodes)
|
|
||||||
self.trace("matchnodes finished -> ", num, "nodes")
|
|
||||||
self.trace.root.indent -= 1
|
|
||||||
if num == 0:
|
|
||||||
raise NoMatch(matching, names[:1])
|
|
||||||
return nodes
|
|
||||||
|
|
||||||
def _matchnodes(
|
|
||||||
self, matching: Sequence[Union[nodes.Item, nodes.Collector]], names: List[str],
|
|
||||||
) -> Sequence[Union[nodes.Item, nodes.Collector]]:
|
|
||||||
if not matching or not names:
|
if not matching or not names:
|
||||||
return matching
|
result = matching
|
||||||
name = names[0]
|
else:
|
||||||
assert name
|
name = names[0]
|
||||||
nextnames = names[1:]
|
assert name
|
||||||
resultnodes = [] # type: List[Union[nodes.Item, nodes.Collector]]
|
nextnames = names[1:]
|
||||||
for node in matching:
|
resultnodes = [] # type: List[Union[nodes.Item, nodes.Collector]]
|
||||||
if isinstance(node, nodes.Item):
|
for node in matching:
|
||||||
if not names:
|
if isinstance(node, nodes.Item):
|
||||||
resultnodes.append(node)
|
if not names:
|
||||||
continue
|
resultnodes.append(node)
|
||||||
assert isinstance(node, nodes.Collector)
|
continue
|
||||||
key = (type(node), node.nodeid)
|
assert isinstance(node, nodes.Collector)
|
||||||
if key in self._collection_node_cache3:
|
key = (type(node), node.nodeid)
|
||||||
rep = self._collection_node_cache3[key]
|
if key in self._collection_node_cache3:
|
||||||
else:
|
rep = self._collection_node_cache3[key]
|
||||||
rep = collect_one_node(node)
|
else:
|
||||||
self._collection_node_cache3[key] = rep
|
rep = collect_one_node(node)
|
||||||
if rep.passed:
|
self._collection_node_cache3[key] = rep
|
||||||
has_matched = False
|
if rep.passed:
|
||||||
for x in rep.result:
|
has_matched = False
|
||||||
# TODO: Remove parametrized workaround once collection structure contains parametrization.
|
for x in rep.result:
|
||||||
if x.name == name or x.name.split("[")[0] == name:
|
# TODO: Remove parametrized workaround once collection structure contains parametrization.
|
||||||
|
if x.name == name or x.name.split("[")[0] == name:
|
||||||
|
resultnodes.extend(self.matchnodes([x], nextnames))
|
||||||
|
has_matched = True
|
||||||
|
# XXX Accept IDs that don't have "()" for class instances.
|
||||||
|
if not has_matched and len(rep.result) == 1 and x.name == "()":
|
||||||
|
nextnames.insert(0, name)
|
||||||
resultnodes.extend(self.matchnodes([x], nextnames))
|
resultnodes.extend(self.matchnodes([x], nextnames))
|
||||||
has_matched = True
|
else:
|
||||||
# XXX Accept IDs that don't have "()" for class instances.
|
# Report collection failures here to avoid failing to run some test
|
||||||
if not has_matched and len(rep.result) == 1 and x.name == "()":
|
# specified in the command line because the module could not be
|
||||||
nextnames.insert(0, name)
|
# imported (#134).
|
||||||
resultnodes.extend(self.matchnodes([x], nextnames))
|
node.ihook.pytest_collectreport(report=rep)
|
||||||
else:
|
result = resultnodes
|
||||||
# Report collection failures here to avoid failing to run some test
|
|
||||||
# specified in the command line because the module could not be
|
self.trace("matchnodes finished -> ", len(result), "nodes")
|
||||||
# imported (#134).
|
self.trace.root.indent -= 1
|
||||||
node.ihook.pytest_collectreport(report=rep)
|
|
||||||
return resultnodes
|
if not result:
|
||||||
|
raise NoMatch(matching, names[:1])
|
||||||
|
else:
|
||||||
|
return result
|
||||||
|
|
||||||
def genitems(
|
def genitems(
|
||||||
self, node: Union[nodes.Item, nodes.Collector]
|
self, node: Union[nodes.Item, nodes.Collector]
|
||||||
|
|
Loading…
Reference in New Issue