@@ -969,7 +969,7 @@ def test_no_trailing_whitespace_after_inifile_word(testdir):
969
969
class TestProgress :
970
970
971
971
@pytest .fixture
972
- def many_tests_file (self , testdir ):
972
+ def many_tests_files (self , testdir ):
973
973
testdir .makepyfile (
974
974
test_bar = """
975
975
import pytest
@@ -1006,30 +1006,30 @@ def pytest_collection_modifyitems(items, config):
1006
1006
'=* 2 passed in *=' ,
1007
1007
])
1008
1008
1009
- def test_normal (self , many_tests_file , testdir ):
1009
+ def test_normal (self , many_tests_files , testdir ):
1010
1010
output = testdir .runpytest ()
1011
1011
output .stdout .re_match_lines ([
1012
1012
r'test_bar.py \.{10} \s+ \[ 50%\]' ,
1013
1013
r'test_foo.py \.{5} \s+ \[ 75%\]' ,
1014
1014
r'test_foobar.py \.{5} \s+ \[100%\]' ,
1015
1015
])
1016
1016
1017
- def test_verbose (self , many_tests_file , testdir ):
1017
+ def test_verbose (self , many_tests_files , testdir ):
1018
1018
output = testdir .runpytest ('-v' )
1019
1019
output .stdout .re_match_lines ([
1020
1020
r'test_bar.py::test_bar\[0\] PASSED \s+ \[ 5%\]' ,
1021
1021
r'test_foo.py::test_foo\[4\] PASSED \s+ \[ 75%\]' ,
1022
1022
r'test_foobar.py::test_foobar\[4\] PASSED \s+ \[100%\]' ,
1023
1023
])
1024
1024
1025
- def test_xdist_normal (self , many_tests_file , testdir ):
1025
+ def test_xdist_normal (self , many_tests_files , testdir ):
1026
1026
pytest .importorskip ('xdist' )
1027
1027
output = testdir .runpytest ('-n2' )
1028
1028
output .stdout .re_match_lines ([
1029
1029
r'\.{20} \s+ \[100%\]' ,
1030
1030
])
1031
1031
1032
- def test_xdist_verbose (self , many_tests_file , testdir ):
1032
+ def test_xdist_verbose (self , many_tests_files , testdir ):
1033
1033
pytest .importorskip ('xdist' )
1034
1034
output = testdir .runpytest ('-n2' , '-v' )
1035
1035
output .stdout .re_match_lines_random ([
@@ -1038,10 +1038,85 @@ def test_xdist_verbose(self, many_tests_file, testdir):
1038
1038
r'\[gw\d\] \[\s*\d+%\] PASSED test_foobar.py::test_foobar\[1\]' ,
1039
1039
])
1040
1040
1041
- def test_capture_no (self , many_tests_file , testdir ):
1041
+ def test_capture_no (self , many_tests_files , testdir ):
1042
1042
output = testdir .runpytest ('-s' )
1043
1043
output .stdout .re_match_lines ([
1044
1044
r'test_bar.py \.{10}' ,
1045
1045
r'test_foo.py \.{5}' ,
1046
1046
r'test_foobar.py \.{5}' ,
1047
1047
])
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