diff --git a/src/_pytest/python.py b/src/_pytest/python.py index b8b365ad34d..5f2af31e20a 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -286,7 +286,7 @@ def getmodpath(self, stopatmodule=True, includemodule=False): parts.append(name) parts.reverse() s = ".".join(parts) - return s.replace(".[", "[") + return s def reportinfo(self): # XXX caching? diff --git a/testing/test_headline_modpath_param_id.py b/testing/test_headline_modpath_param_id.py new file mode 100644 index 00000000000..6f8b30a6bd3 --- /dev/null +++ b/testing/test_headline_modpath_param_id.py @@ -0,0 +1,24 @@ +import pytest + + +def test_headline_preserves_dot_bracket_in_param_id(testdir): + testdir.makepyfile( + **{ + "test_sample.py": ( + """ + import pytest + + @pytest.mark.parametrize("arg", [0], ids=["a..[b]"]) + def test_boo(arg): + assert False + """ + ) + } + ) + result = testdir.runpytest("-vv") + # Ensure the failure headline contains the exact param id text without mutation + result.stdout.fnmatch_lines([ + "*FAILURES*", + "*test_boo[a..[b]]*", + ]) + assert result.ret != 0