我的代码很简单:
def start():
signal(SIGINT, lambda signal, frame: raise SystemExit())
startTCPServer()
所以我用信号处理注册我的应用程序SIGINT
,然后我启动一个 TCP 侦听器。
这是我的问题:
如何使用 python 代码发送 SIGINT 信号?
如何测试应用程序收到 SIGINT 信号是否会引发 SystemExit 异常?
如果我跑start()
在我的测试中,它会阻塞,我如何向它发送信号?
首先,测试信号itself是功能测试或集成测试,而不是单元测试。看单元测试、功能测试、验收测试和集成测试之间有什么区别? https://stackoverflow.com/questions/4904096/whats-the-difference-between-unit-functional-acceptance-and-integration-test
您可以将 Python 脚本作为子进程运行subprocess.Popen() https://docs.python.org/2/library/subprocess.html#subprocess.Popen,然后使用Popen.send_signal() method https://docs.python.org/2/library/subprocess.html#subprocess.Popen.send_signal向该进程发送信号,然后测试该进程是否已退出Popen.poll() https://docs.python.org/2/library/subprocess.html#subprocess.Popen.poll.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)