@@ -1122,6 +1122,160 @@ def test_fail_once(self):
11221122 self .check_executed_tests (output , [testname ],
11231123 rerun = {testname : "test_fail_once" })
11241124
1125+ def test_rerun_setup_class_hook_failure (self ):
1126+ # FAILURE then FAILURE
1127+ code = textwrap .dedent ("""
1128+ import unittest
1129+
1130+ class ExampleTests(unittest.TestCase):
1131+ @classmethod
1132+ def setUpClass(self):
1133+ raise RuntimeError('Fail')
1134+
1135+ def test_success(self):
1136+ return
1137+ """ )
1138+ testname = self .create_test (code = code )
1139+
1140+ output = self .run_tests ("-w" , testname , exitcode = EXITCODE_BAD_TEST )
1141+ self .check_executed_tests (output , testname ,
1142+ failed = [testname ],
1143+ rerun = {testname : "ExampleTests" })
1144+
1145+ def test_rerun_teardown_class_hook_failure (self ):
1146+ # FAILURE then FAILURE
1147+ code = textwrap .dedent ("""
1148+ import unittest
1149+
1150+ class ExampleTests(unittest.TestCase):
1151+ @classmethod
1152+ def tearDownClass(self):
1153+ raise RuntimeError('Fail')
1154+
1155+ def test_success(self):
1156+ return
1157+ """ )
1158+ testname = self .create_test (code = code )
1159+
1160+ output = self .run_tests ("-w" , testname , exitcode = EXITCODE_BAD_TEST )
1161+ self .check_executed_tests (output , testname ,
1162+ failed = [testname ],
1163+ rerun = {testname : "ExampleTests" })
1164+
1165+ def test_rerun_setup_module_hook_failure (self ):
1166+ # FAILURE then FAILURE
1167+ code = textwrap .dedent ("""
1168+ import unittest
1169+
1170+ def setUpModule():
1171+ raise RuntimeError('Fail')
1172+
1173+ class ExampleTests(unittest.TestCase):
1174+ def test_success(self):
1175+ return
1176+ """ )
1177+ testname = self .create_test (code = code )
1178+
1179+ output = self .run_tests ("-w" , testname , exitcode = EXITCODE_BAD_TEST )
1180+ self .check_executed_tests (output , testname ,
1181+ failed = [testname ],
1182+ rerun = {testname : testname })
1183+
1184+ def test_rerun_teardown_module_hook_failure (self ):
1185+ # FAILURE then FAILURE
1186+ code = textwrap .dedent ("""
1187+ import unittest
1188+
1189+ def tearDownModule():
1190+ raise RuntimeError('Fail')
1191+
1192+ class ExampleTests(unittest.TestCase):
1193+ def test_success(self):
1194+ return
1195+ """ )
1196+ testname = self .create_test (code = code )
1197+
1198+ output = self .run_tests ("-w" , testname , exitcode = EXITCODE_BAD_TEST )
1199+ self .check_executed_tests (output , testname ,
1200+ failed = [testname ],
1201+ rerun = {testname : testname })
1202+
1203+ def test_rerun_setup_hook_failure (self ):
1204+ # FAILURE then FAILURE
1205+ code = textwrap .dedent ("""
1206+ import unittest
1207+
1208+ class ExampleTests(unittest.TestCase):
1209+ def setUp(self):
1210+ raise RuntimeError('Fail')
1211+
1212+ def test_success(self):
1213+ return
1214+ """ )
1215+ testname = self .create_test (code = code )
1216+
1217+ output = self .run_tests ("-w" , testname , exitcode = EXITCODE_BAD_TEST )
1218+ self .check_executed_tests (output , testname ,
1219+ failed = [testname ],
1220+ rerun = {testname : "test_success" })
1221+
1222+ def test_rerun_teardown_hook_failure (self ):
1223+ # FAILURE then FAILURE
1224+ code = textwrap .dedent ("""
1225+ import unittest
1226+
1227+ class ExampleTests(unittest.TestCase):
1228+ def tearDown(self):
1229+ raise RuntimeError('Fail')
1230+
1231+ def test_success(self):
1232+ return
1233+ """ )
1234+ testname = self .create_test (code = code )
1235+
1236+ output = self .run_tests ("-w" , testname , exitcode = EXITCODE_BAD_TEST )
1237+ self .check_executed_tests (output , testname ,
1238+ failed = [testname ],
1239+ rerun = {testname : "test_success" })
1240+
1241+ def test_rerun_async_setup_hook_failure (self ):
1242+ # FAILURE then FAILURE
1243+ code = textwrap .dedent ("""
1244+ import unittest
1245+
1246+ class ExampleTests(unittest.IsolatedAsyncioTestCase):
1247+ async def asyncSetUp(self):
1248+ raise RuntimeError('Fail')
1249+
1250+ async def test_success(self):
1251+ return
1252+ """ )
1253+ testname = self .create_test (code = code )
1254+
1255+ output = self .run_tests ("-w" , testname , exitcode = EXITCODE_BAD_TEST )
1256+ self .check_executed_tests (output , testname ,
1257+ failed = [testname ],
1258+ rerun = {testname : "test_success" })
1259+
1260+ def test_rerun_async_teardown_hook_failure (self ):
1261+ # FAILURE then FAILURE
1262+ code = textwrap .dedent ("""
1263+ import unittest
1264+
1265+ class ExampleTests(unittest.IsolatedAsyncioTestCase):
1266+ async def asyncTearDown(self):
1267+ raise RuntimeError('Fail')
1268+
1269+ async def test_success(self):
1270+ return
1271+ """ )
1272+ testname = self .create_test (code = code )
1273+
1274+ output = self .run_tests ("-w" , testname , exitcode = EXITCODE_BAD_TEST )
1275+ self .check_executed_tests (output , testname ,
1276+ failed = [testname ],
1277+ rerun = {testname : "test_success" })
1278+
11251279 def test_no_tests_ran (self ):
11261280 code = textwrap .dedent ("""
11271281 import unittest
0 commit comments