28
28
ROOT_DIR = os .path .abspath (os .path .normpath (ROOT_DIR ))
29
29
LOG_PREFIX = r'[0-9]+:[0-9]+:[0-9]+ (?:load avg: [0-9]+\.[0-9]{2} )?'
30
30
31
+ EXITCODE_BAD_TEST = 2
32
+ EXITCODE_ENV_CHANGED = 3
33
+ EXITCODE_NO_TESTS_RAN = 4
34
+ EXITCODE_INTERRUPTED = 130
35
+
31
36
TEST_INTERRUPTED = textwrap .dedent ("""
32
37
from signal import SIGINT, raise_signal
33
38
try:
@@ -497,7 +502,7 @@ def list_regex(line_format, tests):
497
502
result .append ('INTERRUPTED' )
498
503
if not any ((good , result , failed , interrupted , skipped ,
499
504
env_changed , fail_env_changed )):
500
- result .append ("NO TEST RUN " )
505
+ result .append ("NO TESTS RAN " )
501
506
elif not result :
502
507
result .append ('SUCCESS' )
503
508
result = ', ' .join (result )
@@ -707,7 +712,7 @@ def test_failing(self):
707
712
test_failing = self .create_test ('failing' , code = code )
708
713
tests = [test_ok , test_failing ]
709
714
710
- output = self .run_tests (* tests , exitcode = 2 )
715
+ output = self .run_tests (* tests , exitcode = EXITCODE_BAD_TEST )
711
716
self .check_executed_tests (output , tests , failed = test_failing )
712
717
713
718
def test_resources (self ):
@@ -748,13 +753,14 @@ def test_random(self):
748
753
test = self .create_test ('random' , code )
749
754
750
755
# first run to get the output with the random seed
751
- output = self .run_tests ('-r' , test )
756
+ output = self .run_tests ('-r' , test , exitcode = EXITCODE_NO_TESTS_RAN )
752
757
randseed = self .parse_random_seed (output )
753
758
match = self .regex_search (r'TESTRANDOM: ([0-9]+)' , output )
754
759
test_random = int (match .group (1 ))
755
760
756
761
# try to reproduce with the random seed
757
- output = self .run_tests ('-r' , '--randseed=%s' % randseed , test )
762
+ output = self .run_tests ('-r' , '--randseed=%s' % randseed , test ,
763
+ exitcode = EXITCODE_NO_TESTS_RAN )
758
764
randseed2 = self .parse_random_seed (output )
759
765
self .assertEqual (randseed2 , randseed )
760
766
@@ -813,7 +819,7 @@ def test_fromfile(self):
813
819
def test_interrupted (self ):
814
820
code = TEST_INTERRUPTED
815
821
test = self .create_test ('sigint' , code = code )
816
- output = self .run_tests (test , exitcode = 130 )
822
+ output = self .run_tests (test , exitcode = EXITCODE_INTERRUPTED )
817
823
self .check_executed_tests (output , test , omitted = test ,
818
824
interrupted = True )
819
825
@@ -838,7 +844,7 @@ def test_slowest_interrupted(self):
838
844
args = ("--slowest" , "-j2" , test )
839
845
else :
840
846
args = ("--slowest" , test )
841
- output = self .run_tests (* args , exitcode = 130 )
847
+ output = self .run_tests (* args , exitcode = EXITCODE_INTERRUPTED )
842
848
self .check_executed_tests (output , test ,
843
849
omitted = test , interrupted = True )
844
850
@@ -878,7 +884,7 @@ def test_run(self):
878
884
builtins.__dict__['RUN'] = 1
879
885
""" )
880
886
test = self .create_test ('forever' , code = code )
881
- output = self .run_tests ('--forever' , test , exitcode = 2 )
887
+ output = self .run_tests ('--forever' , test , exitcode = EXITCODE_BAD_TEST )
882
888
self .check_executed_tests (output , [test ]* 3 , failed = test )
883
889
884
890
def check_leak (self , code , what ):
@@ -887,7 +893,7 @@ def check_leak(self, code, what):
887
893
filename = 'reflog.txt'
888
894
self .addCleanup (os_helper .unlink , filename )
889
895
output = self .run_tests ('--huntrleaks' , '3:3:' , test ,
890
- exitcode = 2 ,
896
+ exitcode = EXITCODE_BAD_TEST ,
891
897
stderr = subprocess .STDOUT )
892
898
self .check_executed_tests (output , [test ], failed = test )
893
899
@@ -969,7 +975,7 @@ def test_crashed(self):
969
975
crash_test = self .create_test (name = "crash" , code = code )
970
976
971
977
tests = [crash_test ]
972
- output = self .run_tests ("-j2" , * tests , exitcode = 2 )
978
+ output = self .run_tests ("-j2" , * tests , exitcode = EXITCODE_BAD_TEST )
973
979
self .check_executed_tests (output , tests , failed = crash_test ,
974
980
randomize = True )
975
981
@@ -1069,7 +1075,8 @@ def test_env_changed(self):
1069
1075
self .check_executed_tests (output , [testname ], env_changed = testname )
1070
1076
1071
1077
# fail with --fail-env-changed
1072
- output = self .run_tests ("--fail-env-changed" , testname , exitcode = 3 )
1078
+ output = self .run_tests ("--fail-env-changed" , testname ,
1079
+ exitcode = EXITCODE_ENV_CHANGED )
1073
1080
self .check_executed_tests (output , [testname ], env_changed = testname ,
1074
1081
fail_env_changed = True )
1075
1082
@@ -1088,7 +1095,7 @@ def test_fail_always(self):
1088
1095
""" )
1089
1096
testname = self .create_test (code = code )
1090
1097
1091
- output = self .run_tests ("-w" , testname , exitcode = 2 )
1098
+ output = self .run_tests ("-w" , testname , exitcode = EXITCODE_BAD_TEST )
1092
1099
self .check_executed_tests (output , [testname ],
1093
1100
failed = testname , rerun = {testname : "test_fail_always" })
1094
1101
@@ -1123,7 +1130,8 @@ def test_bug(self):
1123
1130
""" )
1124
1131
testname = self .create_test (code = code )
1125
1132
1126
- output = self .run_tests (testname , "-m" , "nosuchtest" , exitcode = 0 )
1133
+ output = self .run_tests (testname , "-m" , "nosuchtest" ,
1134
+ exitcode = EXITCODE_NO_TESTS_RAN )
1127
1135
self .check_executed_tests (output , [testname ], no_test_ran = testname )
1128
1136
1129
1137
def test_no_tests_ran_skip (self ):
@@ -1136,7 +1144,7 @@ def test_skipped(self):
1136
1144
""" )
1137
1145
testname = self .create_test (code = code )
1138
1146
1139
- output = self .run_tests (testname , exitcode = 0 )
1147
+ output = self .run_tests (testname )
1140
1148
self .check_executed_tests (output , [testname ])
1141
1149
1142
1150
def test_no_tests_ran_multiple_tests_nonexistent (self ):
@@ -1150,7 +1158,8 @@ def test_bug(self):
1150
1158
testname = self .create_test (code = code )
1151
1159
testname2 = self .create_test (code = code )
1152
1160
1153
- output = self .run_tests (testname , testname2 , "-m" , "nosuchtest" , exitcode = 0 )
1161
+ output = self .run_tests (testname , testname2 , "-m" , "nosuchtest" ,
1162
+ exitcode = EXITCODE_NO_TESTS_RAN )
1154
1163
self .check_executed_tests (output , [testname , testname2 ],
1155
1164
no_test_ran = [testname , testname2 ])
1156
1165
@@ -1198,7 +1207,8 @@ def test_garbage(self):
1198
1207
""" )
1199
1208
testname = self .create_test (code = code )
1200
1209
1201
- output = self .run_tests ("--fail-env-changed" , testname , exitcode = 3 )
1210
+ output = self .run_tests ("--fail-env-changed" , testname ,
1211
+ exitcode = EXITCODE_ENV_CHANGED )
1202
1212
self .check_executed_tests (output , [testname ],
1203
1213
env_changed = [testname ],
1204
1214
fail_env_changed = True )
@@ -1224,7 +1234,8 @@ def test_sleep(self):
1224
1234
""" )
1225
1235
testname = self .create_test (code = code )
1226
1236
1227
- output = self .run_tests ("-j2" , "--timeout=1.0" , testname , exitcode = 2 )
1237
+ output = self .run_tests ("-j2" , "--timeout=1.0" , testname ,
1238
+ exitcode = EXITCODE_BAD_TEST )
1228
1239
self .check_executed_tests (output , [testname ],
1229
1240
failed = testname )
1230
1241
self .assertRegex (output ,
@@ -1256,7 +1267,8 @@ def test_unraisable_exc(self):
1256
1267
""" )
1257
1268
testname = self .create_test (code = code )
1258
1269
1259
- output = self .run_tests ("--fail-env-changed" , "-v" , testname , exitcode = 3 )
1270
+ output = self .run_tests ("--fail-env-changed" , "-v" , testname ,
1271
+ exitcode = EXITCODE_ENV_CHANGED )
1260
1272
self .check_executed_tests (output , [testname ],
1261
1273
env_changed = [testname ],
1262
1274
fail_env_changed = True )
@@ -1287,7 +1299,8 @@ def test_threading_excepthook(self):
1287
1299
""" )
1288
1300
testname = self .create_test (code = code )
1289
1301
1290
- output = self .run_tests ("--fail-env-changed" , "-v" , testname , exitcode = 3 )
1302
+ output = self .run_tests ("--fail-env-changed" , "-v" , testname ,
1303
+ exitcode = EXITCODE_ENV_CHANGED )
1291
1304
self .check_executed_tests (output , [testname ],
1292
1305
env_changed = [testname ],
1293
1306
fail_env_changed = True )
@@ -1328,7 +1341,7 @@ def test_print_warning(self):
1328
1341
for option in ("-v" , "-W" ):
1329
1342
with self .subTest (option = option ):
1330
1343
cmd = ["--fail-env-changed" , option , testname ]
1331
- output = self .run_tests (* cmd , exitcode = 3 )
1344
+ output = self .run_tests (* cmd , exitcode = EXITCODE_ENV_CHANGED )
1332
1345
self .check_executed_tests (output , [testname ],
1333
1346
env_changed = [testname ],
1334
1347
fail_env_changed = True )
@@ -1373,7 +1386,8 @@ def test_leak_tmp_file(self):
1373
1386
""" )
1374
1387
testnames = [self .create_test (code = code ) for _ in range (3 )]
1375
1388
1376
- output = self .run_tests ("--fail-env-changed" , "-v" , "-j2" , * testnames , exitcode = 3 )
1389
+ output = self .run_tests ("--fail-env-changed" , "-v" , "-j2" , * testnames ,
1390
+ exitcode = EXITCODE_ENV_CHANGED )
1377
1391
self .check_executed_tests (output , testnames ,
1378
1392
env_changed = testnames ,
1379
1393
fail_env_changed = True ,
0 commit comments