|
15 | 15 | import stat
|
16 | 16 | import sys
|
17 | 17 | import textwrap
|
18 |
| -import time |
19 | 18 |
|
20 | 19 | from pathlib import Path
|
21 | 20 | from typing import Any
|
|
29 | 28 |
|
30 | 29 | from tests import testenv
|
31 | 30 | 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 |
33 | 32 |
|
34 | 33 |
|
35 | 34 | class ProcessTest(CoverageTest):
|
@@ -458,37 +457,6 @@ def test_os_exit(self, patch: bool) -> None:
|
458 | 457 | else:
|
459 | 458 | assert seen < total_lines
|
460 | 459 |
|
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 |
| - |
492 | 460 | def test_warnings_during_reporting(self) -> None:
|
493 | 461 | # While fixing issue #224, the warnings were being printed far too
|
494 | 462 | # often. Make sure they're not any more.
|
@@ -728,24 +696,25 @@ def test_save_signal_usr1(self) -> None:
|
728 | 696 | import os
|
729 | 697 | import signal
|
730 | 698 |
|
731 |
| - print(f"Sending SIGUSR1 to process {os.getpid()}") |
| 699 | + print(f"Sending SIGUSR1 to myself") |
732 | 700 | os.kill(os.getpid(), signal.SIGUSR1)
|
733 | 701 | os.kill(os.getpid(), signal.SIGKILL)
|
734 | 702 |
|
735 |
| - print('Done and goodbye') |
| 703 | + print("Done and goodbye") |
736 | 704 | """)
|
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") |
739 | 711 | 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") |
744 | 713 | 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 | + ---------------------------------------------- |
749 | 718 | TOTAL 6 2 67%
|
750 | 719 | """)
|
751 | 720 |
|
|
0 commit comments