python - 如何测试中断处理程序是否与 pytest 一起工作?

ubo*_*ngo 7 python interrupt pytest

我在类和以下方法中有一个中断处理程序:

def interruptHandler(self, signal, frame):
    """ Catches SIGINT and SIGTERM to allow proper shutdown of all threads etc."""
    self.stopWorker()
    print("interrupt") # the print message is just for me to see if it works
Run Code Online (Sandbox Code Playgroud)

当我按 control + c 时,我从中断处理程序中收到打印消息,因此该方法很好。但是当我为它编写 pytest 时,我不知道如何断言 SIGINT。当我想强制中断时

worker.interruptHandler(signal.sigint)

我收到一个错误,提示我缺少参数框架。