diff --git a/AUTHORS b/AUTHORS index 5ab1c2f7a03..1a8c5306f75 100644 --- a/AUTHORS +++ b/AUTHORS @@ -326,6 +326,7 @@ Thomas Grainger Thomas Hisch Tim Hoffmann Tim Strazny +Tobias Diez Tom Dalton Tom Viner Tomáš Gavenčiak diff --git a/changelog/9823.improvement.rst b/changelog/9823.improvement.rst new file mode 100644 index 00000000000..0a14cab6743 --- /dev/null +++ b/changelog/9823.improvement.rst @@ -0,0 +1 @@ +Improved error message that is shown when no collector is found for a given file. diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 8f590754ae0..f2f0c667141 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -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 diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 71d3cc23a2e..92661b0f23a 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -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}", "", ] ) diff --git a/testing/test_config.py b/testing/test_config.py index 6784809e097..b2c74085eae 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -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