@@ -705,7 +705,7 @@ class SigtermTest(CoverageTest):
705
705
"""Tests of our handling of SIGTERM."""
706
706
707
707
@pytest .mark .parametrize ("sigterm" , [False , True ])
708
- def test_sigterm_saves_data (self , sigterm : bool ) -> None :
708
+ def test_sigterm_multiprocessing_saves_data (self , sigterm : bool ) -> None :
709
709
# A terminated process should save its coverage data.
710
710
self .make_file ("clobbered.py" , """\
711
711
import multiprocessing
@@ -751,6 +751,28 @@ def subproc(x):
751
751
expected = "clobbered.py 17 5 71% 5-10"
752
752
assert self .squeezed_lines (out )[2 ] == expected
753
753
754
+ def test_sigterm_threading_saves_data (self ) -> None :
755
+ # A terminated process should save its coverage data.
756
+ self .make_file ("handler.py" , """\
757
+ import os, signal
758
+
759
+ print("START", flush=True)
760
+ print("SIGTERM", flush=True)
761
+ os.kill(os.getpid(), signal.SIGTERM)
762
+ print("NOT HERE", flush=True)
763
+ """ )
764
+ self .make_file (".coveragerc" , """\
765
+ [run]
766
+ # The default concurrency option.
767
+ concurrency = thread
768
+ sigterm = true
769
+ """ )
770
+ out = self .run_command ("coverage run handler.py" )
771
+ assert out == "START\n SIGTERM\n Terminated\n "
772
+ out = self .run_command ("coverage report -m" )
773
+ expected = "handler.py 5 1 80% 6"
774
+ assert self .squeezed_lines (out )[2 ] == expected
775
+
754
776
def test_sigterm_still_runs (self ) -> None :
755
777
# A terminated process still runs its own SIGTERM handler.
756
778
self .make_file ("handler.py" , """\
0 commit comments