File tree Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -822,7 +822,7 @@ def do_help(
822
822
823
823
def do_signal_save (self , _signum : int , _frame : types .FrameType | None ) -> None :
824
824
""" Signal handler to save coverage report """
825
- print ("Saving coverage data ..." )
825
+ print ("Saving coverage data ..." , flush = True )
826
826
self .coverage .save ()
827
827
828
828
def do_run (self , options : optparse .Values , args : list [str ]) -> int :
Original file line number Diff line number Diff line change 13
13
import os
14
14
import os .path
15
15
import re
16
+ import shlex
16
17
import shutil
17
18
import subprocess
18
19
import sys
@@ -47,7 +48,7 @@ def _correct_encoding() -> str:
47
48
return encoding
48
49
49
50
50
- def subprocess_popen (cmd : str ) -> subprocess .Popen [bytes ]:
51
+ def subprocess_popen (cmd : str , shell = True ) -> subprocess .Popen [bytes ]:
51
52
"""Run a command in a subprocess.
52
53
53
54
Returns the Popen object.
@@ -66,9 +67,12 @@ def subprocess_popen(cmd: str) -> subprocess.Popen[bytes]:
66
67
sub_env = dict (os .environ )
67
68
sub_env ["PYTHONIOENCODING" ] = _correct_encoding ()
68
69
70
+ if not shell :
71
+ cmd = shlex .split (cmd )
72
+
69
73
proc = subprocess .Popen (
70
74
cmd ,
71
- shell = True ,
75
+ shell = shell ,
72
76
env = sub_env ,
73
77
stdin = subprocess .PIPE ,
74
78
stdout = subprocess .PIPE ,
Original file line number Diff line number Diff line change @@ -465,21 +465,29 @@ def test_os_exit(self, patch: bool) -> None:
465
465
def test_save_signal (self , send : bool ) -> None :
466
466
self .make_file ("loop.py" , """\
467
467
import time
468
+ print("Starting", flush=True)
468
469
while True:
469
470
time.sleep(.01)
470
471
""" )
471
- proc = subprocess_popen ("coverage run --save-signal=USR1 loop.py" )
472
+ proc = subprocess_popen ("coverage run --save-signal=USR1 loop.py" , shell = False )
472
473
time .sleep (.25 )
473
474
if send :
474
475
proc .send_signal (signal .SIGUSR1 )
475
- time .sleep (.91 )
476
+ time .sleep (.1 )
476
477
proc .kill ()
477
- proc .communicate ()
478
- proc .wait ()
478
+ proc .wait (timeout = .25 )
479
+ stdout , _ = proc .communicate ()
480
+ if not env .PYPY :
481
+ # Not sure why, PyPy doesn't get the output.
482
+ assert b"Starting" in stdout
479
483
if send :
480
484
self .assert_exists (".coverage" )
485
+ if not env .PYPY :
486
+ assert b"Saving coverage data" in stdout
481
487
else :
482
488
self .assert_doesnt_exist (".coverage" )
489
+ if not env .PYPY :
490
+ assert b"Saving coverage data" not in stdout
483
491
484
492
def test_warnings_during_reporting (self ) -> None :
485
493
# While fixing issue #224, the warnings were being printed far too
You can’t perform that action at this time.
0 commit comments