Skip to content

Commit 1e8e46d

Browse files
authored
Merge pull request #9823 from tobiasdiez/patch-1
Clarify error message in case no collectors are found for a file
2 parents 28e8c85 + 7df4057 commit 1e8e46d

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ Thomas Grainger
326326
Thomas Hisch
327327
Tim Hoffmann
328328
Tim Strazny
329+
Tobias Diez
329330
Tom Dalton
330331
Tom Viner
331332
Tomáš Gavenčiak

changelog/9823.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved error message that is shown when no collector is found for a given file.

src/_pytest/main.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,14 @@ def perform_collect(
645645
self.trace.root.indent -= 1
646646
if self._notfound:
647647
errors = []
648-
for arg, cols in self._notfound:
649-
line = f"(no name {arg!r} in any of {cols!r})"
650-
errors.append(f"not found: {arg}\n{line}")
648+
for arg, collectors in self._notfound:
649+
if collectors:
650+
errors.append(
651+
f"not found: {arg}\n(no name {arg!r} in any of {collectors!r})"
652+
)
653+
else:
654+
errors.append(f"found no collectors for {arg}")
655+
651656
raise UsageError(*errors)
652657
if not genitems:
653658
items = rep.result

testing/acceptance_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ def test_not_collectable_arguments(self, pytester: Pytester) -> None:
186186
assert result.ret == ExitCode.USAGE_ERROR
187187
result.stderr.fnmatch_lines(
188188
[
189-
f"ERROR: not found: {p2}",
190-
f"(no name {str(p2)!r} in any of [[][]])",
189+
f"ERROR: found no collectors for {p2}",
191190
"",
192191
]
193192
)

testing/test_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,8 +1855,7 @@ def test_config_blocked_default_plugins(pytester: Pytester, plugin: str) -> None
18551855
assert result.ret == ExitCode.USAGE_ERROR
18561856
result.stderr.fnmatch_lines(
18571857
[
1858-
"ERROR: not found: */test_config_blocked_default_plugins.py",
1859-
"(no name '*/test_config_blocked_default_plugins.py' in any of [])",
1858+
"ERROR: found no collectors for */test_config_blocked_default_plugins.py",
18601859
]
18611860
)
18621861
return

0 commit comments

Comments
 (0)