From 8e991a622c571f7cf0e0e1bff5cbcde8cbe2e014 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 21 Feb 2020 15:24:12 +0100 Subject: [PATCH] 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 --- testing/test_terminal.py | 57 +++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 3a49a3f13..38ca1957a 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -170,26 +170,53 @@ class TestTerminal: def test_itemreport_subclasses_show_subclassed_file(self, testdir): testdir.makepyfile( - test_p1=""" + **{ + "tests/test_p1": """ class BaseTests(object): + fail = False + def test_p1(self): - pass - class TestClass(BaseTests): - pass - """ - ) - p2 = testdir.makepyfile( - test_p2=""" + if self.fail: assert 0 + """, + "tests/test_p2": """ 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.stdout.fnmatch_lines(["*test_p2.py .*", "*1 passed*"]) - result = testdir.runpytest("-vv", p2) + result = testdir.runpytest("tests/test_p2.py", "--rootdir=tests") + result.stdout.fnmatch_lines(["tests/test_p2.py .*", "=* 1 passed in *"]) + + result = testdir.runpytest("-vv", "-rA", "tests/test_p2.py", "--rootdir=tests") 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):