tests: harden/improve test_itemreport_subclasses_show_subclassed_file (#6467)

* tests: harden test_itemreport_subclasses_show_subclassed_file

* extend test_itemreport_subclasses_show_subclassed_file
This commit is contained in:
Daniel Hahler 2020-02-21 15:24:12 +01:00 committed by GitHub
parent b099fcfa33
commit 8e991a622c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 15 deletions

View File

@ -170,26 +170,53 @@ class TestTerminal:
def test_itemreport_subclasses_show_subclassed_file(self, testdir): def test_itemreport_subclasses_show_subclassed_file(self, testdir):
testdir.makepyfile( testdir.makepyfile(
test_p1=""" **{
"tests/test_p1": """
class BaseTests(object): class BaseTests(object):
fail = False
def test_p1(self): def test_p1(self):
pass if self.fail: assert 0
class TestClass(BaseTests): """,
pass "tests/test_p2": """
"""
)
p2 = testdir.makepyfile(
test_p2="""
from test_p1 import BaseTests from test_p1 import BaseTests
class TestMore(BaseTests):
pass class TestMore(BaseTests): pass
""" """,
"tests/test_p3.py": """
from test_p1 import BaseTests
BaseTests.fail = True
class TestMore(BaseTests): pass
""",
}
) )
result = testdir.runpytest(p2) result = testdir.runpytest("tests/test_p2.py", "--rootdir=tests")
result.stdout.fnmatch_lines(["*test_p2.py .*", "*1 passed*"]) result.stdout.fnmatch_lines(["tests/test_p2.py .*", "=* 1 passed in *"])
result = testdir.runpytest("-vv", p2)
result = testdir.runpytest("-vv", "-rA", "tests/test_p2.py", "--rootdir=tests")
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
["*test_p2.py::TestMore::test_p1* <- *test_p1.py*PASSED*"] [
"tests/test_p2.py::TestMore::test_p1 <- test_p1.py PASSED *",
"*= short test summary info =*",
"PASSED tests/test_p2.py::TestMore::test_p1",
]
)
result = testdir.runpytest("-vv", "-rA", "tests/test_p3.py", "--rootdir=tests")
result.stdout.fnmatch_lines(
[
"tests/test_p3.py::TestMore::test_p1 <- test_p1.py FAILED *",
"*_ TestMore.test_p1 _*",
" def test_p1(self):",
"> if self.fail: assert 0",
"E assert 0",
"",
"tests/test_p1.py:5: AssertionError",
"*= short test summary info =*",
"FAILED tests/test_p3.py::TestMore::test_p1 - assert 0",
"*= 1 failed in *",
]
) )
def test_itemreport_directclasses_not_shown_as_subclasses(self, testdir): def test_itemreport_directclasses_not_shown_as_subclasses(self, testdir):