pytest-dev/pytest · error · ValueError
found 2 or more testreports matching {inamepart!r}: {values}
Error message
found 2 or more testreports matching {inamepart!r}: {values} What it means
Raised by Pytester.matchreport when more than one report matches the inamepart filter, making the selection ambiguous. Because matchreport must return exactly one report, an ambiguous match is rejected. The matching logic compares inamepart against each part of the node id split on '::', so a short or common substring matches many tests.
Source
Thrown at src/_pytest/pytester.py:379
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,
names: Literal["pytest_runtest_logreport"],
) -> Sequence[TestReport]: ...
@overload
def getfailures(View on GitHub (pinned to 98b357f69e)
Solutions
- Pass a more specific inamepart that uniquely identifies a single test (include the function name and, if needed, the parametrization id).
- Pass the 'when' argument (e.g. when="call") to narrow which phase's report is matched.
- Use getreports() directly and filter in your own test code when ambiguity is expected.
- Rename colliding tests so node ids are distinguishable.
Example fix
// before
rep = reprec.matchreport("test_") # matches all tests
// after
rep = reprec.matchreport("test_login::test_success", when="call") Defensive patterns
Strategy: validation
Validate before calling
candidates = [r for r in reprec.getreports()
if "test_foo" in r.nodeid.split("::")]
if len(candidates) > 1:
raise AssertionError(f"ambiguous; refine inamepart. matches: {candidates}")
rep = reprec.matchreport("test_foo::specific_case") Try / catch
try:
rep = reprec.matchreport(inamepart, when="call")
except ValueError as e:
if "2 or more" in str(e):
inamepart = make_it_more_specific(inamepart)
rep = reprec.matchreport(inamepart, when="call")
else:
raise Prevention
- Pass full node-id-style substrings including parametrization ids.
- Specify the 'when' argument to disambiguate phases.
- Use unique test function names.
When it happens
Trigger: Calling matchreport with an inamepart that is a substring of multiple test node ids (e.g. 'test_' matches every test), or when setup/teardown/call reports all match because 'when' is not specified and reports failed.
Common situations: Tests with shared name prefixes; passing a generic substring instead of a full test name; parametrized tests whose ids share a stem; not passing the 'when' argument when multiple phases produced non-passed reports.
Related errors
- could not find test report matching {inamepart!r}: no test r
- 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/8bc888de769557cb.json.
Report an issue: GitHub.