pytest-dev/pytest · error · UsageError

found no collectors for {arg}

Error message

found no collectors for {arg}

What it means

The companion branch at main.py:862 raises 'found no collectors for {arg}' when a collection argument matched ZERO collector objects (the collectors list is empty/falsy), as opposed to error 112 where collectors existed but matched no item. This means pytest could not turn the argument into any collector at all.

Source

Thrown at src/_pytest/main.py:862

                initialpaths_with_parents.append(collection_argument.path)
                initialpaths_with_parents.extend(collection_argument.path.parents)
            self._initialpaths = frozenset(initialpaths)
            self._initialpaths_with_parents = frozenset(initialpaths_with_parents)

            rep = collect_one_node(self)
            self.ihook.pytest_collectreport(report=rep)
            self.trace.root.indent -= 1
            if self._notfound:
                errors = []
                for arg, collectors in self._notfound:
                    if collectors:
                        errors.append(
                            f"not found: {arg}\n(no match in any of {collectors!r})"
                        )
                    else:
                        errors.append(f"found no collectors for {arg}")

                raise UsageError(*errors)

            if not genitems:
                items = rep.result
            else:
                if rep.passed:
                    for node in rep.result:
                        self.items.extend(self.genitems(node))

            self.config.pluginmanager.check_pending()
            hook.pytest_collection_modifyitems(
                session=self, config=self.config, items=items
            )
        finally:
            self._notfound = []
            self._initial_parts = []
            self._collection_cache = {}
            hook.pytest_collection_finish(session=self)

View on GitHub (pinned to 0d6fbdeffa)

Solutions

  1. Verify the path points to a python file/module containing tests (named test_*.py / *_test.py by default).
  2. Ensure any custom collector plugin is installed and enabled.
  3. Run 'pytest --collect-only <arg>' to see what pytest can collect.
  4. Check python_files / python_classes / python_functions ini settings if names differ.

Example fix

// before
pytest data/fixtures.json
// after
pytest tests/test_user.py
Defensive patterns

Strategy: validation

Validate before calling

# Confirm pytest can collect the argument
import subprocess, sys
r = subprocess.run([sys.executable,'-m','pytest','--collect-only', arg],
                  capture_output=True, text=True)
if r.returncode != 0 or 'no tests ran' in r.stdout:
    raise SystemExit(f'{arg!r} yields no collectors; check path/plugin/python_files')

Prevention

When it happens

Trigger: Passing an argument that exists on disk but yields no python test collector (e.g. a non-test .txt file with no collect hook); a path that resolves to nothing collectible; a malformed argument with no matching plugin collector.

Common situations: Pointing pytest at a data file or directory with no test modules; a custom collector plugin not loaded; --pyargs referencing a module with no tests; an empty directory given as an argument.

Related errors


AI-assisted analysis of pytest-dev/pytest@0d6fbdeffa (2026-08-11). Data as JSON: /api/errors/7a59e00d16086af8. Report an issue: GitHub.