From 841521fedb9e04a67479b286773a38f0fc4c1c90 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 21 Aug 2020 15:05:54 +0300 Subject: [PATCH] main: only perform one recursive matchnodes call per node --- src/_pytest/main.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 8d898426c..e47752f91 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -764,15 +764,16 @@ class Session(nodes.FSCollector): rep = collect_one_node(node) self._collection_node_cache3[key] = rep if rep.passed: - has_matched = False + 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]: - result.extend(self.matchnodes([x], names[1:])) - has_matched = True + submatching.append(x) + if submatching: + result.extend(self.matchnodes(submatching, names[1:])) # XXX Accept IDs that don't have "()" for class instances. - if not has_matched and len(rep.result) == 1 and x.name == "()": - result.extend(self.matchnodes([x], names)) + 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