forked from pytest-dev/pytest
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Summary
- Parametrized test ids containing the substring ".[" are incorrectly mutated in long report output/headlines: any ".[" becomes "[". Example: "..[" becomes ".[" in the failure header. This also affects tools relying on headlines (e.g., VS Code test discovery heuristics).
Observed failure
bug.py F [100%]
=================================== FAILURES ===================================
_________________________________ test_boo[.[] _________________________________
a = '..['
@pytest.mark.parametrize("a",["..["])
def test_boo(a):
> assert 0
E assert 0
bug.py:6: AssertionError
============================== 1 failed in 0.06s ===============================
The "test_boo[..[]" is rendered as "test_boo[.[]" in the failure headline.
Root cause
- src/_pytest/python.py: in PyobjMixin.getmodpath(), the result is returned as
s.replace(".[", "["). - This was historically intended to avoid dotted paths like
test_gen.[0]from yield-based tests (removed in pytest 4.0). - With yield tests gone, this sanitization is obsolete and now corrupts parameter ids which legitimately contain the sequence ".[".
Proposed fix
- Change getmodpath() to return
sunchanged, and add a brief comment noting yield tests removal.
Reproduction steps
- Create bug.py:
import pytest
@pytest.mark.parametrize("a", ["..["])
def test_boo(a):
assert False
- Run:
pytest -vv bug.py. - Observe the failure headline shows
test_boo[.[]instead oftest_boo[..[].
Acceptance criteria
- Long report failure headlines preserve the exact parameter id text; no mutation of ".[" sequences inside ids.
- Nodeids remain unchanged.
- Add a regression test using pytester that asserts
test_boo[a..[b]]appears unchanged in -vv headline output.
Notes
- Yield tests have been removed since pytest 4.0; no remaining path should produce node segments like
[0]that would justify the sanitization. - No CI run is necessary for this PR per project rules.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels