Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify error message in case no collectors are found for a file #9823

Merged
merged 8 commits into from Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -325,6 +325,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