Skip to content

Commit eec13ba

Browse files
committed
main: get rid of NoMatch
Things are easier to understand without the weird exception.
1 parent c4fd461 commit eec13ba

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/_pytest/main.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,6 @@ def __getattr__(self, name: str):
402402
return x
403403

404404

405-
class NoMatch(Exception):
406-
"""Matching cannot locate matching names."""
407-
408-
409405
class Interrupted(KeyboardInterrupt):
410406
"""Signals that the test run was interrupted."""
411407

@@ -598,7 +594,7 @@ def perform_collect( # noqa: F811
598594
self.trace("perform_collect", self, args)
599595
self.trace.root.indent += 1
600596

601-
self._notfound = [] # type: List[Tuple[str, NoMatch]]
597+
self._notfound = [] # type: List[Tuple[str, Sequence[nodes.Collector]]]
602598
self._initial_parts = [] # type: List[Tuple[py.path.local, List[str]]]
603599
self.items = [] # type: List[nodes.Item]
604600

@@ -619,8 +615,8 @@ def perform_collect( # noqa: F811
619615
self.trace.root.indent -= 1
620616
if self._notfound:
621617
errors = []
622-
for arg, exc in self._notfound:
623-
line = "(no name {!r} in any of {!r})".format(arg, exc.args[0])
618+
for arg, cols in self._notfound:
619+
line = "(no name {!r} in any of {!r})".format(arg, cols)
624620
errors.append("not found: {}\n{}".format(arg, line))
625621
raise UsageError(*errors)
626622
if not genitems:
@@ -644,14 +640,7 @@ def collect(self) -> Iterator[Union[nodes.Item, nodes.Collector]]:
644640
for fspath, parts in self._initial_parts:
645641
self.trace("processing argument", (fspath, parts))
646642
self.trace.root.indent += 1
647-
try:
648-
yield from self._collect(fspath, parts)
649-
except NoMatch as exc:
650-
report_arg = "::".join((str(fspath), *parts))
651-
# we are inside a make_report hook so
652-
# we cannot directly pass through the exception
653-
self._notfound.append((report_arg, exc))
654-
643+
yield from self._collect(fspath, parts)
655644
self.trace.root.indent -= 1
656645
self._collection_node_cache1.clear()
657646
self._collection_node_cache2.clear()
@@ -727,7 +716,10 @@ def _collect(
727716
self._collection_node_cache1[argpath] = col
728717
m = self.matchnodes(col, names)
729718
if not m:
730-
raise NoMatch(col)
719+
report_arg = "::".join((str(argpath), *names))
720+
self._notfound.append((report_arg, col))
721+
return
722+
731723
# If __init__.py was the only file requested, then the matched node will be
732724
# the corresponding Package, and the first yielded item will be the __init__
733725
# Module itself, so just use that. If this special case isn't taken, then all

0 commit comments

Comments
 (0)