Skip to content

Commit eeeb196

Browse files
authored
Merge pull request #6202 from linw1995/fix_getmodpath
Fix incorrect result of getmodpath method.
2 parents bebd804 + 5d5f480 commit eeeb196

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ Virgil Dupras
262262
Vitaly Lashmanov
263263
Vlad Dragos
264264
Volodymyr Piskun
265+
Wei Lin
265266
Wil Cooley
266267
William Lee
267268
Wim Glenn

changelog/6189.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix incorrect result of ``getmodpath`` method.

src/_pytest/python.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ def getmodpath(self, stopatmodule=True, includemodule=False):
285285
break
286286
parts.append(name)
287287
parts.reverse()
288-
s = ".".join(parts)
289-
return s.replace(".[", "[")
288+
return ".".join(parts)
290289

291290
def reportinfo(self):
292291
# XXX caching?

testing/test_collection.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,8 @@ def test_2():
685685
def test_example_items1(self, testdir):
686686
p = testdir.makepyfile(
687687
"""
688+
import pytest
689+
688690
def testone():
689691
pass
690692
@@ -693,19 +695,24 @@ def testmethod_one(self):
693695
pass
694696
695697
class TestY(TestX):
696-
pass
698+
@pytest.mark.parametrize("arg0", [".["])
699+
def testmethod_two(self, arg0):
700+
pass
697701
"""
698702
)
699703
items, reprec = testdir.inline_genitems(p)
700-
assert len(items) == 3
704+
assert len(items) == 4
701705
assert items[0].name == "testone"
702706
assert items[1].name == "testmethod_one"
703707
assert items[2].name == "testmethod_one"
708+
assert items[3].name == "testmethod_two[.[]"
704709

705710
# let's also test getmodpath here
706711
assert items[0].getmodpath() == "testone"
707712
assert items[1].getmodpath() == "TestX.testmethod_one"
708713
assert items[2].getmodpath() == "TestY.testmethod_one"
714+
# PR #6202: Fix incorrect result of getmodpath method. (Resolves issue #6189)
715+
assert items[3].getmodpath() == "TestY.testmethod_two[.[]"
709716

710717
s = items[0].getmodpath(stopatmodule=False)
711718
assert s.endswith("test_example_items1.testone")

0 commit comments

Comments
 (0)