Skip to content

Commit a50d6d7

Browse files
committed
test: --save-signal was a bit overtested, remove the difficult one
1 parent abe8254 commit a50d6d7

File tree

3 files changed

+17
-52
lines changed

3 files changed

+17
-52
lines changed

coverage/cmdline.py

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

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

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

tests/helpers.py

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

5049

51-
def subprocess_popen(cmd: str, shell: bool=True) -> subprocess.Popen[bytes]:
50+
def subprocess_popen(cmd: str) -> subprocess.Popen[bytes]:
5251
"""Run a command in a subprocess.
5352
5453
Returns the Popen object.
@@ -67,12 +66,9 @@ def subprocess_popen(cmd: str, shell: bool=True) -> subprocess.Popen[bytes]:
6766
sub_env = dict(os.environ)
6867
sub_env["PYTHONIOENCODING"] = _correct_encoding()
6968

70-
if not shell:
71-
cmd = shlex.split(cmd) # type: ignore[assignment]
72-
7369
proc = subprocess.Popen(
7470
cmd,
75-
shell=shell,
71+
shell=True,
7672
env=sub_env,
7773
stdin=subprocess.PIPE,
7874
stdout=subprocess.PIPE,

tests/test_process.py

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import stat
1616
import sys
1717
import textwrap
18-
import time
1918

2019
from pathlib import Path
2120
from typing import Any
@@ -29,7 +28,7 @@
2928

3029
from tests import testenv
3130
from tests.coveragetest import CoverageTest, TESTS_DIR
32-
from tests.helpers import re_line, re_lines, re_lines_text, subprocess_popen
31+
from tests.helpers import re_line, re_lines, re_lines_text
3332

3433

3534
class ProcessTest(CoverageTest):
@@ -458,37 +457,6 @@ def test_os_exit(self, patch: bool) -> None:
458457
else:
459458
assert seen < total_lines
460459

461-
@pytest.mark.skipif(env.WINDOWS, reason="Windows can't do --save-signal")
462-
@pytest.mark.parametrize("send", [False, True])
463-
def test_save_signal(self, send: bool) -> None:
464-
# PyPy on Ubuntu seems to need more time for things to happen.
465-
base_time = 0.0
466-
if env.PYPY and env.LINUX:
467-
base_time += 0.75
468-
if env.METACOV:
469-
base_time += 1.0
470-
self.make_file("loop.py", """\
471-
import time
472-
print("Starting", flush=True)
473-
while True:
474-
time.sleep(.02)
475-
""")
476-
proc = subprocess_popen("coverage run --save-signal=USR1 loop.py", shell=False)
477-
time.sleep(base_time + .25)
478-
if send:
479-
proc.send_signal(signal.SIGUSR1)
480-
time.sleep(base_time + .25)
481-
proc.kill()
482-
proc.wait(timeout=base_time + .25)
483-
stdout, _ = proc.communicate()
484-
assert b"Starting" in stdout
485-
if send:
486-
self.assert_exists(".coverage")
487-
assert b"Saving coverage data" in stdout
488-
else:
489-
self.assert_doesnt_exist(".coverage")
490-
assert b"Saving coverage data" not in stdout
491-
492460
def test_warnings_during_reporting(self) -> None:
493461
# While fixing issue #224, the warnings were being printed far too
494462
# often. Make sure they're not any more.
@@ -728,24 +696,25 @@ def test_save_signal_usr1(self) -> None:
728696
import os
729697
import signal
730698
731-
print(f"Sending SIGUSR1 to process {os.getpid()}")
699+
print(f"Sending SIGUSR1 to myself")
732700
os.kill(os.getpid(), signal.SIGUSR1)
733701
os.kill(os.getpid(), signal.SIGKILL)
734702
735-
print('Done and goodbye')
703+
print("Done and goodbye")
736704
""")
737-
covered_lines = 4
738-
self.run_command(f"coverage run --save-signal USR1 {test_file}", status=-signal.SIGKILL)
705+
out = self.run_command(
706+
f"coverage run --save-signal=USR1 {test_file}",
707+
status=-signal.SIGKILL,
708+
)
709+
# `startswith` because on Linux it also prints "Killed"
710+
assert out.startswith("Sending SIGUSR1 to myself\nSaving coverage data...\n")
739711
self.assert_exists(".coverage")
740-
data = coverage.CoverageData()
741-
data.read()
742-
assert line_counts(data)[test_file] == covered_lines
743-
out = self.run_command("coverage report")
712+
out = self.run_command("coverage report -m")
744713
assert out == textwrap.dedent("""\
745-
Name Stmts Miss Cover
746-
------------------------------------
747-
dummy_hello.py 6 2 67%
748-
------------------------------------
714+
Name Stmts Miss Cover Missing
715+
----------------------------------------------
716+
dummy_hello.py 6 2 67% 6-8
717+
----------------------------------------------
749718
TOTAL 6 2 67%
750719
""")
751720

0 commit comments

Comments
 (0)