pytest-dev/pytest · error · ValueError
could not find test report matching
Error message
could not find test report matching {inamepart!r}: no test reports at all! What it means
Thrown by Pytester.RunResult.matchreport() when filtering captured pytest hook reports yields zero matches for the given inamepart/when filter. It means either no tests ran (no reports collected at all) or none matched the node-id fragment you passed. The 'no test reports at all!' wording specifically indicates the values list is empty.
Solutions
- Inspect pytester.runpytest().parseoutcomes() to confirm tests actually ran and collected.
- Verify the inamepart string is an exact '::'-delimited segment of the test's nodeid (e.g. 'test_foo', not 'foo').
- Remove or correct the `when` argument if you only have setup/teardown reports.
- Use matchreport with no inamepart to get the single report when only one test exists.
Example fix
// before
rep = reprec.matchreport("test_foo", when="call")
// after
result = pytester.runpytest("-q")
assert result.ret == 0
reprec = result.reprec
reports = reprec.getreports("pytest_runtest_logreport")
assert reports, "no reports collected - did the test run?"
rep = reprec.matchreport("test_foo") Defensive patterns
Strategy: validation
Validate before calling
reports = reprec.getreports("pytest_runtest_logreport")
if not reports:
pytest.fail("no test reports collected - did the test run?")
matches = [r for r in reports if 'test_foo' in r.nodeid.split('::')]
assert len(matches) == 1, f"expected 1 match, got {len(matches)}"
rep = reprec.matchreport('test_foo') Prevention
- Inspect getreports() before matchreport() to confirm reports exist.
- Use full '::'-delimited nodeid segments, never substrings.
- Avoid passing when= unless you know the phase.
When it happens
Trigger: Calling pytester.matchreport('test_foo') after a pytester run where (a) collection failed so no TestReports exist, (b) the test name fragment doesn't appear as a '::'-delimited segment of any captured nodeid, or (c) the `when` filter excludes all reports (e.g. when='call' but only setup reports exist).
Common situations: Writing pytester-based plugin tests; typos in the test function name passed to matchreport; expecting a 'call' phase report when the test errored during setup; calling matchreport before runpytest_inprocess populated the HookRecorder.
Related errors
- found 2 or more testreports matching
- ext must not be None
- line not found in output
- pytester.makefile expects a file extension, try .
- absolute tolerance can't be negative
AI-assisted analysis of pytest-dev/pytest@0d6fbdeffa (2026-08-11).
Data as JSON: /api/errors/0de2bd5c1e8154f5.
Report an issue: GitHub.
Appendix: 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 0d6fbdeffa)