pytest-dev/pytest · error · UsageError
not found: {arg} (no match in any of {collectors!r})
Error message
not found: {arg}
(no match in any of {collectors!r}) What it means
main.py:862 reports 'not found: {arg}\n(no match in any of {collectors!r})' during collection when a command-line argument resolved to one or more collector objects but none of them produced matching items for the given selection. The argument was located as a collector but the '::part' or pattern did not match any test inside. This is a UsageError raised after _notfound entries accumulate.
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
- Run 'pytest path/to/test_file.py --collect-only' to list the exact valid nodeids.
- Correct the '::part' spelling in the command to match an existing test/class.
- If the test was removed, update CI configs and scripts referencing it.
- Use --co -q to get machine-readable nodeids for copy-paste.
Example fix
// before pytest tests/test_user.py::TestUser::test_delet # typo // after pytest tests/test_user.py::TestUser::test_delete
Defensive patterns
Strategy: validation
Validate before calling
# Before running, list valid nodeids and verify the target exists
import subprocess, sys
out = subprocess.run([sys.executable,'-m','pytest','--collect-only','-q', path],
capture_output=True, text=True).stdout
nodeids = {l.strip() for l in out.splitlines() if '::' in l}
assert target in nodeids, f'{target!r} not in collected nodeids' Prevention
- Generate nodeids via --collect-only -q and copy exact strings.
- Update CI references when tests are renamed.
- Run a collect-only step in CI to fail fast on stale nodeids.
When it happens
Trigger: Running 'pytest path/to/test_file.py::TestClass::test_wrong_name' where the method does not exist; selecting a class/function name that has a typo; using a nodeid whose '::' parts reference an absent nested item.
Common situations: Renaming a test and forgetting to update CI invocation strings; stale nodeids copied from old runs; selecting parametrized IDs that no longer exist; wrong class name in a deselect/keyword context.
Related errors
- found no collectors for {arg}
- package argument cannot contain :: selection parts: {arg}
- directory argument cannot contain :: selection parts: {arg}
- path cannot contain [] parametrization: {arg}
- file or directory not found: {arg}
AI-assisted analysis of pytest-dev/pytest@0d6fbdeffa (2026-08-11).
Data as JSON: /api/errors/5117955129ee94d6.
Report an issue: GitHub.