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