(Unit) Test python signal handler
问题 I have a simple Python service, where there is a loop that performs some action infinitely. On various signals, sys.exit(0) is called, which causes SystemExit to be raised and then some cleanup should happen if it can. In a test, i.e. standard unittest.TestCase , I would like to test that this cleanup happens and the loop exits. However, I'm stuck on even getting the signal to be triggered / SystemExit to be raised. # service.py import signal import sys import time def main(): def signal