How to really test signal handling in Python?

后端 未结 2 1990
北荒
北荒 2021-02-20 08:34

My code is simple:

def start():
    signal(SIGINT, lambda signal, frame: raise SystemExit())
    startTCPServer()

So I register my application

2条回答
  •  [愿得一人]
    2021-02-20 08:53

    First of, testing the signal itself is a functional or integration test, not a unit test. See What's the difference between unit, functional, acceptance, and integration tests?

    You can run your Python script as a subprocess with subprocess.Popen(), then use the Popen.send_signal() method to send signals to that process, then test that the process has exited with Popen.poll().

提交回复
热议问题