Skip to content

Commit 42cb985

Browse files
committed
test: fix save-signal test
1 parent 962a30f commit 42cb985

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

coverage/cmdline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ def do_help(
822822

823823
def do_signal_save(self, _signum: int, _frame: types.FrameType | None) -> None:
824824
""" Signal handler to save coverage report """
825-
print("Saving coverage data ...")
825+
print("Saving coverage data ...", flush=True)
826826
self.coverage.save()
827827

828828
def do_run(self, options: optparse.Values, args: list[str]) -> int:

tests/helpers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import os.path
1515
import re
16+
import shlex
1617
import shutil
1718
import subprocess
1819
import sys
@@ -47,7 +48,7 @@ def _correct_encoding() -> str:
4748
return encoding
4849

4950

50-
def subprocess_popen(cmd: str) -> subprocess.Popen[bytes]:
51+
def subprocess_popen(cmd: str, shell=True) -> subprocess.Popen[bytes]:
5152
"""Run a command in a subprocess.
5253
5354
Returns the Popen object.
@@ -66,9 +67,12 @@ def subprocess_popen(cmd: str) -> subprocess.Popen[bytes]:
6667
sub_env = dict(os.environ)
6768
sub_env["PYTHONIOENCODING"] = _correct_encoding()
6869

70+
if not shell:
71+
cmd = shlex.split(cmd)
72+
6973
proc = subprocess.Popen(
7074
cmd,
71-
shell=True,
75+
shell=shell,
7276
env=sub_env,
7377
stdin=subprocess.PIPE,
7478
stdout=subprocess.PIPE,

tests/test_process.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,21 +465,29 @@ def test_os_exit(self, patch: bool) -> None:
465465
def test_save_signal(self, send: bool) -> None:
466466
self.make_file("loop.py", """\
467467
import time
468+
print("Starting", flush=True)
468469
while True:
469470
time.sleep(.01)
470471
""")
471-
proc = subprocess_popen("coverage run --save-signal=USR1 loop.py")
472+
proc = subprocess_popen("coverage run --save-signal=USR1 loop.py", shell=False)
472473
time.sleep(.25)
473474
if send:
474475
proc.send_signal(signal.SIGUSR1)
475-
time.sleep(.91)
476+
time.sleep(.1)
476477
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
479483
if send:
480484
self.assert_exists(".coverage")
485+
if not env.PYPY:
486+
assert b"Saving coverage data" in stdout
481487
else:
482488
self.assert_doesnt_exist(".coverage")
489+
if not env.PYPY:
490+
assert b"Saving coverage data" not in stdout
483491

484492
def test_warnings_during_reporting(self) -> None:
485493
# While fixing issue #224, the warnings were being printed far too

0 commit comments

Comments
 (0)