pytest-dev/pytest · error · ValueError
could not find test report matching {inamepart!r}: no test r
Error message
could not find test report matching {inamepart!r}: no test reports at all! What it means
Raised by Pytester.matchreport when it iterates over collected pytest reports and finds zero that match the given inamepart substring of a node id. The message explicitly notes 'no test reports at all!', meaning the run produced no collect/test reports to match against. This is a pytester-internal helper used in tests that assert on report outcomes.
Source
Thrown at src/_pytest/pytester.py:374
inamepart: str = "",
names: str | Iterable[str] = (
"pytest_runtest_logreport",
"pytest_collectreport",
),
when: str | None = None,
) -> CollectReport | TestReport:
"""Return a testreport whose dotted import path matches."""
values = []
for rep in self.getreports(names=names):
if not when and rep.when != "call" and rep.passed:
# setup/teardown passing reports - let's ignore those
continue
if when and rep.when != when:
continue
if not inamepart or inamepart in rep.nodeid.split("::"):
values.append(rep)
if not values:
raise ValueError(
f"could not find test report matching {inamepart!r}: "
"no test reports at all!"
)
if len(values) > 1:
raise ValueError(
f"found 2 or more testreports matching {inamepart!r}: {values}"
)
return values[0]
@overload
def getfailures(
self,
names: Literal["pytest_collectreport"],
) -> Sequence[CollectReport]: ...
@overload
def getfailures(
self,View on GitHub (pinned to 98b357f69e)
Solutions
- Ensure runpytest(...) (or runpytest_inprocess/runpytest_subprocess) is actually called and its result stored before calling matchreport.
- Inspect reprec.getreports() / the captured output to confirm the run collected tests and produced reports.
- Fix the underlying collection/import error so the spawned run emits reports.
- Pass the correct inamepart matching the test's node id, or pass '' to match any report.
Example fix
// before
reprec = pytester.runpytest_inprocess()
rep = reprec.matchreport("test_bar") # name typo, or no run at all
// after
reprec = pytester.runpytest_inprocess()
assert reprec.getreports() # sanity check reports exist
rep = reprec.matchreport("test_foo") Defensive patterns
Strategy: validation
Validate before calling
reports = reprec.getreports()
if not reports:
raise AssertionError("pytest run produced no reports; check collection errors first")
rep = reprec.matchreport("test_foo") Try / catch
try:
rep = reprec.matchreport("test_foo")
except ValueError as e:
print(reprec.stdout.str()) # debug the actual run output
raise Prevention
- Always call runpytest and store the result before asserting on reports.
- Sanity-check reprec.getreports() is non-empty.
- Verify the spawned pytest collected the expected tests via stdout.
When it happens
Trigger: Calling result.matchreport('test_foo') on a RunResult/LineMatcher whose underlying pytest run collected nothing, failed at collection, or whose reports were never recorded (e.g. runpytest was never invoked, or the run crashed before reporting).
Common situations: Forgetting to call runpytest_inprocess/subprocess before asserting on reports; a typo in the test name passed to matchreport; the spawned pytest subprocess errored out at import time before any test ran; a conftest.py sys.excepthook or collection error swallowed reporting.
Related errors
- found 2 or more testreports matching {inamepart!r}: {values}
- Pytest terminal summary report not found
- line {fnline!r} not found in output
- invalid type for lines2: {type(lines2).__name__}
- approx() is not supported in a boolean context. Did you mean
AI-assisted analysis of pytest-dev/pytest@98b357f69e (2026-08-04).
Data as JSON: /data/errors/0de2bd5c1e8154f5.json.
Report an issue: GitHub.