From 0c6b2f39b2fa4532813b5995038af6d143405c88 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Fri, 21 Aug 2020 14:45:03 +0300 Subject: [PATCH] main: move NoMatch raising to _collect() This is a more sensible interface for matchnodes. This also fixes a sort-of bug where a recursive call to matchnodes raises NoMatch which would terminate the entire tree, even if other branches may find a match. Though I don't think it's actually possible. --- src/_pytest/main.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 1f7340720..8d898426c 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -724,6 +724,8 @@ class Session(nodes.FSCollector): if col: self._collection_node_cache1[argpath] = col m = self.matchnodes(col, names) + if not m: + raise NoMatch(col) # If __init__.py was the only file requested, then the matched node will be # the corresponding Package, and the first yielded item will be the __init__ # Module itself, so just use that. If this special case isn't taken, then all @@ -780,10 +782,7 @@ class Session(nodes.FSCollector): self.trace("matchnodes finished -> ", len(result), "nodes") self.trace.root.indent -= 1 - if not result: - raise NoMatch(matching, names[:1]) - else: - return result + return result def genitems( self, node: Union[nodes.Item, nodes.Collector]