@@ -270,7 +270,7 @@ def test_missing_source_file(self) -> None:
270
270
271
271
self .run_command ("coverage run fleeting.py" )
272
272
os .remove ("fleeting.py" )
273
- out = self .run_command ("coverage html -d htmlcov" )
273
+ out = self .run_command ("coverage html -d htmlcov" , status = 1 )
274
274
assert re .search ("No source for code: '.*fleeting.py'" , out )
275
275
assert "Traceback" not in out
276
276
@@ -282,10 +282,9 @@ def test_missing_source_file(self) -> None:
282
282
283
283
self .run_command ("coverage run fleeting" )
284
284
os .remove ("fleeting" )
285
- status , out = self .run_command_status ("coverage html -d htmlcov" )
285
+ out = self .run_command ("coverage html -d htmlcov" , status = 1 )
286
286
assert re .search ("No source for code: '.*fleeting'" , out )
287
287
assert "Traceback" not in out
288
- assert status == 1
289
288
290
289
def test_running_missing_file (self ) -> None :
291
290
status , out = self .run_command_status ("coverage run xyzzy.py" )
@@ -310,8 +309,8 @@ def f2():
310
309
311
310
# The important thing is for "coverage run" and "python" to report the
312
311
# same traceback.
313
- status , out = self .run_command_status ("coverage run throw.py" )
314
- out2 = self .run_command ("python throw.py" )
312
+ out = self .run_command ("coverage run throw.py" , status = 1 )
313
+ out2 = self .run_command ("python throw.py" , status = 1 )
315
314
if env .PYPY :
316
315
# PyPy has an extra frame in the traceback for some reason
317
316
out2 = re_lines_text ("toplevel" , out2 , match = False )
@@ -322,7 +321,6 @@ def f2():
322
321
msg = f'File "{ re .escape (path )} ", line 8, in f2'
323
322
assert re .search (msg , out )
324
323
assert 'raise MyException("hey!")' in out
325
- assert status == 1
326
324
327
325
def test_code_exits (self ) -> None :
328
326
self .make_file ("exit.py" , """\
@@ -483,13 +481,13 @@ def test_warns_if_never_run(self) -> None:
483
481
# Note: the name of the function can't have "warning" in it, or the
484
482
# absolute path of the file will have "warning" in it, and an assertion
485
483
# will fail.
486
- out = self .run_command ("coverage run i_dont_exist.py" )
484
+ out = self .run_command ("coverage run i_dont_exist.py" , status = 1 )
487
485
path = python_reported_file ('i_dont_exist.py' )
488
486
assert f"No file to run: '{ path } '" in out
489
487
assert "warning" not in out
490
488
assert "Exception" not in out
491
489
492
- out = self .run_command ("coverage run -m no_such_module" )
490
+ out = self .run_command ("coverage run -m no_such_module" , status = 1 )
493
491
assert (
494
492
("No module named no_such_module" in out ) or
495
493
("No module named 'no_such_module'" in out )
@@ -873,8 +871,8 @@ def test_pythonsafepath_dashm(self) -> None:
873
871
self .make_file ("with_main/__main__.py" , f .read ())
874
872
875
873
self .set_environ ("PYTHONSAFEPATH" , "1" )
876
- expected = self .run_command ("python -m with_main" )
877
- actual = self .run_command ("coverage run -m with_main" )
874
+ expected = self .run_command ("python -m with_main" , status = 1 )
875
+ actual = self .run_command ("coverage run -m with_main" , status = 1 )
878
876
assert re .search ("No module named '?with_main'?" , actual )
879
877
assert re .search ("No module named '?with_main'?" , expected )
880
878
@@ -1039,10 +1037,8 @@ def excepthook(*args):
1039
1037
1040
1038
raise RuntimeError('Error Outside')
1041
1039
""" )
1042
- cov_st , cov_out = self .run_command_status ("coverage run excepthook_throw.py" )
1043
- py_st , py_out = self .run_command_status ("python excepthook_throw.py" )
1044
- assert cov_st == py_st
1045
- assert cov_st == 1
1040
+ cov_out = self .run_command ("coverage run excepthook_throw.py" , status = 1 )
1041
+ py_out = self .run_command ("python excepthook_throw.py" , status = 1 )
1046
1042
assert "in excepthook" in py_out
1047
1043
assert cov_out == py_out
1048
1044
@@ -1062,8 +1058,9 @@ def test_wrong_alias_doesnt_work(self) -> None:
1062
1058
# "coverage2" doesn't work on py3
1063
1059
assert sys .version_info [0 ] == 3 # Let us know when Python 4 is out...
1064
1060
badcmd = "coverage2"
1065
- out = self .run_command (badcmd )
1061
+ status , out = self .run_command_status (badcmd )
1066
1062
assert "Code coverage for Python" not in out
1063
+ assert status != 0
1067
1064
1068
1065
def test_specific_alias_works (self ) -> None :
1069
1066
# "coverage-3.9" works on py3.9
@@ -1077,7 +1074,7 @@ def test_specific_alias_works(self) -> None:
1077
1074
"coverage-%d.%d" % sys .version_info [:2 ],
1078
1075
])
1079
1076
def test_aliases_used_in_messages (self , cmd : str ) -> None :
1080
- out = self .run_command (f"{ cmd } foobar" )
1077
+ out = self .run_command (f"{ cmd } foobar" , status = 1 )
1081
1078
assert "Unknown command: 'foobar'" in out
1082
1079
assert f"Use '{ cmd } help' for help" in out
1083
1080
@@ -1228,7 +1225,7 @@ def test_core_request_sysmon(self) -> None:
1228
1225
def test_core_request_nosuchcore (self ) -> None :
1229
1226
self .set_environ ("COVERAGE_CORE" , "nosuchcore" )
1230
1227
self .make_file ("numbers.py" , "print(123, 456)" )
1231
- out = self .run_command ("coverage run numbers.py" )
1228
+ out = self .run_command ("coverage run numbers.py" , status = 1 )
1232
1229
assert "Unknown core value: 'nosuchcore'\n " in out
1233
1230
assert "123 456" not in out
1234
1231
@@ -1276,7 +1273,7 @@ def test_removing_directory(self) -> None:
1276
1273
1277
1274
def test_removing_directory_with_error (self ) -> None :
1278
1275
self .make_file ("bug806.py" , self .BUG_806 )
1279
- out = self .run_command ("coverage run bug806.py" )
1276
+ out = self .run_command ("coverage run bug806.py" , status = 1 )
1280
1277
path = python_reported_file ('bug806.py' )
1281
1278
# Python 3.11 adds an extra line to the traceback.
1282
1279
# Check that the lines we expect are there.
0 commit comments