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