Skip to content

Commit fa941ad

Browse files
committed
Add a test for a name conflict with test class methods.
1 parent 7c3e4d1 commit fa941ad

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tests/test_03_class.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,36 @@ def test_e(self):
8282
*::TestClassNamed::test_d PASSED
8383
*::TestClassNamed::test_e SKIPPED
8484
""")
85+
86+
87+
@pytest.mark.xfail(reason="Issue #6")
88+
def test_class_default_name(ctestdir):
89+
"""For methods of test classes, the default name is the method name.
90+
This may cause conflicts if there is a function having the same
91+
name outside the class. Note how the method test_a() of class
92+
TestClass shadows the failure of function test_a().
93+
"""
94+
ctestdir.makepyfile("""
95+
import pytest
96+
97+
@pytest.mark.dependency()
98+
def test_a():
99+
assert False
100+
101+
class TestClass(object):
102+
103+
@pytest.mark.dependency()
104+
def test_a(self):
105+
pass
106+
107+
@pytest.mark.dependency(depends=["test_a"])
108+
def test_b():
109+
pass
110+
""")
111+
result = ctestdir.runpytest("--verbose")
112+
result.assert_outcomes(passed=1, skipped=1, failed=1)
113+
result.stdout.fnmatch_lines("""
114+
*::test_a FAILED
115+
*::TestClass::test_a PASSED
116+
*::test_b SKIPPED
117+
""")

0 commit comments

Comments
 (0)