Merge pull request #9823 from tobiasdiez/patch-1

Clarify error message in case no collectors are found for a file
This commit is contained in:
Bruno Oliveira 2022-04-22 07:28:08 -03:00 committed by GitHub
commit 1e8e46d456
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 7 deletions

View File

@ -326,6 +326,7 @@ Thomas Grainger
Thomas Hisch
Tim Hoffmann
Tim Strazny
Tobias Diez
Tom Dalton
Tom Viner
Tomáš Gavenčiak

View File

@ -0,0 +1 @@
Improved error message that is shown when no collector is found for a given file.

View File

@ -645,9 +645,14 @@ 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 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

View File

@ -186,8 +186,7 @@ class TestGeneralUsage:
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}",
"",
]
)

View File

@ -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