From 1f10c59cd3a716bda3c7d4a91cdaa6fb9e910ef8 Mon Sep 17 00:00:00 2001 From: Tobias Diez Date: Sun, 27 Mar 2022 16:30:57 +0200 Subject: [PATCH] Clarify error message in case no collectors are found for a file --- src/_pytest/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 8f590754a..fc42beb5a 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -645,9 +645,12 @@ class Session(nodes.FSCollector): self.trace.root.indent -= 1 if self._notfound: errors = [] - for arg, cols in self._notfound: - line = f"(no name {arg!r} in any of {cols!r})" - errors.append(f"not found: {arg}\n{line}") + for arg, collectors in self._notfound: + if cols: + errors.append(f"not found: {arg}\n(no name {arg!r} in any of {collectors!r})") + else: + errors.append(f"found no collectors for {arg}") + raise UsageError(*errors) if not genitems: items = rep.result