Skip to content

Commit

Permalink
Merge pull request #9823 from tobiasdiez/patch-1
Browse files Browse the repository at this point in the history
Clarify error message in case no collectors are found for a file
  • Loading branch information
nicoddemus committed Apr 22, 2022
2 parents 28e8c85 + 7df4057 commit 1e8e46d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -326,6 +326,7 @@ Thomas Grainger
Thomas Hisch
Tim Hoffmann
Tim Strazny
Tobias Diez
Tom Dalton
Tom Viner
Tomáš Gavenčiak
Expand Down
1 change: 1 addition & 0 deletions changelog/9823.improvement.rst
@@ -0,0 +1 @@
Improved error message that is shown when no collector is found for a given file.
11 changes: 8 additions & 3 deletions src/_pytest/main.py
Expand Up @@ -645,9 +645,14 @@ def perform_collect(
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 collectors:
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
Expand Down
3 changes: 1 addition & 2 deletions testing/acceptance_test.py
Expand Up @@ -186,8 +186,7 @@ def test_not_collectable_arguments(self, pytester: Pytester) -> None:
assert result.ret == ExitCode.USAGE_ERROR
result.stderr.fnmatch_lines(
[
f"ERROR: not found: {p2}",
f"(no name {str(p2)!r} in any of [[][]])",
f"ERROR: found no collectors for {p2}",
"",
]
)
Expand Down
3 changes: 1 addition & 2 deletions testing/test_config.py
Expand Up @@ -1855,8 +1855,7 @@ def test_config_blocked_default_plugins(pytester: Pytester, plugin: str) -> None
assert result.ret == ExitCode.USAGE_ERROR
result.stderr.fnmatch_lines(
[
"ERROR: not found: */test_config_blocked_default_plugins.py",
"(no name '*/test_config_blocked_default_plugins.py' in any of [])",
"ERROR: found no collectors for */test_config_blocked_default_plugins.py",
]
)
return
Expand Down

0 comments on commit 1e8e46d

Please sign in to comment.