@@ -969,7 +969,7 @@ def test_no_trailing_whitespace_after_inifile_word(testdir):
969969class TestProgress :
970970
971971 @pytest .fixture
972- def many_tests_file (self , testdir ):
972+ def many_tests_files (self , testdir ):
973973 testdir .makepyfile (
974974 test_bar = """
975975 import pytest
@@ -1006,30 +1006,30 @@ def pytest_collection_modifyitems(items, config):
10061006 '=* 2 passed in *=' ,
10071007 ])
10081008
1009- def test_normal (self , many_tests_file , testdir ):
1009+ def test_normal (self , many_tests_files , testdir ):
10101010 output = testdir .runpytest ()
10111011 output .stdout .re_match_lines ([
10121012 r'test_bar.py \.{10} \s+ \[ 50%\]' ,
10131013 r'test_foo.py \.{5} \s+ \[ 75%\]' ,
10141014 r'test_foobar.py \.{5} \s+ \[100%\]' ,
10151015 ])
10161016
1017- def test_verbose (self , many_tests_file , testdir ):
1017+ def test_verbose (self , many_tests_files , testdir ):
10181018 output = testdir .runpytest ('-v' )
10191019 output .stdout .re_match_lines ([
10201020 r'test_bar.py::test_bar\[0\] PASSED \s+ \[ 5%\]' ,
10211021 r'test_foo.py::test_foo\[4\] PASSED \s+ \[ 75%\]' ,
10221022 r'test_foobar.py::test_foobar\[4\] PASSED \s+ \[100%\]' ,
10231023 ])
10241024
1025- def test_xdist_normal (self , many_tests_file , testdir ):
1025+ def test_xdist_normal (self , many_tests_files , testdir ):
10261026 pytest .importorskip ('xdist' )
10271027 output = testdir .runpytest ('-n2' )
10281028 output .stdout .re_match_lines ([
10291029 r'\.{20} \s+ \[100%\]' ,
10301030 ])
10311031
1032- def test_xdist_verbose (self , many_tests_file , testdir ):
1032+ def test_xdist_verbose (self , many_tests_files , testdir ):
10331033 pytest .importorskip ('xdist' )
10341034 output = testdir .runpytest ('-n2' , '-v' )
10351035 output .stdout .re_match_lines_random ([
@@ -1038,10 +1038,85 @@ def test_xdist_verbose(self, many_tests_file, testdir):
10381038 r'\[gw\d\] \[\s*\d+%\] PASSED test_foobar.py::test_foobar\[1\]' ,
10391039 ])
10401040
1041- def test_capture_no (self , many_tests_file , testdir ):
1041+ def test_capture_no (self , many_tests_files , testdir ):
10421042 output = testdir .runpytest ('-s' )
10431043 output .stdout .re_match_lines ([
10441044 r'test_bar.py \.{10}' ,
10451045 r'test_foo.py \.{5}' ,
10461046 r'test_foobar.py \.{5}' ,
10471047 ])
1048+
1049+
1050+ class TestProgressWithTeardown :
1051+ """Ensure we show the correct percentages for tests that fail during teardown (#3088)"""
1052+
1053+ @pytest .fixture
1054+ def contest_with_teardown_fixture (self , testdir ):
1055+ testdir .makeconftest ('''
1056+ import pytest
1057+
1058+ @pytest.fixture
1059+ def fail_teardown():
1060+ yield
1061+ assert False
1062+ ''' )
1063+
1064+ @pytest .fixture
1065+ def many_files (self , testdir , contest_with_teardown_fixture ):
1066+ testdir .makepyfile (
1067+ test_bar = '''
1068+ import pytest
1069+ @pytest.mark.parametrize('i', range(5))
1070+ def test_bar(fail_teardown, i):
1071+ pass
1072+ ''' ,
1073+ test_foo = '''
1074+ import pytest
1075+ @pytest.mark.parametrize('i', range(15))
1076+ def test_foo(fail_teardown, i):
1077+ pass
1078+ ''' ,
1079+ )
1080+
1081+ def test_teardown_simple (self , testdir , contest_with_teardown_fixture ):
1082+ testdir .makepyfile ('''
1083+ def test_foo(fail_teardown):
1084+ pass
1085+ ''' )
1086+ output = testdir .runpytest ()
1087+ output .stdout .re_match_lines ([
1088+ r'test_teardown_simple.py \.E\s+\[100%\]' ,
1089+ ])
1090+
1091+ def test_teardown_with_test_also_failing (self , testdir , contest_with_teardown_fixture ):
1092+ testdir .makepyfile ('''
1093+ def test_foo(fail_teardown):
1094+ assert False
1095+ ''' )
1096+ output = testdir .runpytest ()
1097+ output .stdout .re_match_lines ([
1098+ r'test_teardown_with_test_also_failing.py FE\s+\[100%\]' ,
1099+ ])
1100+
1101+ def test_teardown_many (self , testdir , many_files ):
1102+ output = testdir .runpytest ()
1103+ output .stdout .re_match_lines ([
1104+ r'test_bar.py (\.E){5}\s+\[ 25%\]' ,
1105+ r'test_foo.py (\.E){15}\s+\[100%\]' ,
1106+ ])
1107+
1108+ def test_teardown_many_verbose (self , testdir , many_files ):
1109+ output = testdir .runpytest ('-v' )
1110+ output .stdout .re_match_lines ([
1111+ r'test_bar.py::test_bar\[0\] PASSED\s+\[ 5%\]' ,
1112+ r'test_bar.py::test_bar\[0\] ERROR\s+\[ 5%\]' ,
1113+ r'test_bar.py::test_bar\[4\] PASSED\s+\[ 25%\]' ,
1114+ r'test_bar.py::test_bar\[4\] ERROR\s+\[ 25%\]' ,
1115+ ])
1116+
1117+ def test_xdist_normal (self , many_files , testdir ):
1118+ pytest .importorskip ('xdist' )
1119+ output = testdir .runpytest ('-n2' )
1120+ output .stdout .re_match_lines ([
1121+ r'[\.E]{40} \s+ \[100%\]' ,
1122+ ])
0 commit comments