2016-04-22 93 views
2

我正在设计一个应该运行直到遇到异常的py.test。如果测试从未遇到异常,它应该继续运行剩下的时间或直到我发送一个SIGINT/SIGTERM。长时间运行py.test在第一次失败时停止

是否存在一种编程方式来告诉py.test在第一次失败时停止运行,而不是必须在命令行执行此操作?

谢谢。

+0

的文档,你能告诉你的,你是如何编程调用pytest代码? –

回答

0

您可以随时使用try/except经典方法。

while True: 
    try: 
     #do your stuff 
    except: 
     #This code is called if an exception is thrown (error handling) 
     break #breaking the loop 
5

请在结帐http://pytest.org/latest/usage.html#usage

py.test -x   # stop after first failure 
py.test --maxfail=2 # stop after two failures 
+0

这是一个命令行选项,因此不是编程接口。 – Matt

+0

你是如何调用py.test的? –

+0

py.test file.py – Matt