2014-01-17 48 views
1

我有使用funcargs在我的测试:pytest。执行所有拆卸模块

def test_name(fooarg1, fooarg2):

个个都pytest_funcarg__工厂,返回request.cached_setup,所以个个都安装/拆卸部分。

有时我有一个fooarg2拆解的问题,所以我在这里引发异常。在这种情况下,忽略所有其他teardowns(fooarg1.teardown,teardown_module等),然后转到pytest_session已完成的部分。

pytest中是否有任何选项不会收集异常并执行所有剩余的拆解功能?

回答

0

在您的拆卸功能中,您可以捕获错误并进行打印。

def teardown(): # this is the teardown function with the error 
    try: 
     # the original code with error 
    except: 
     import traceback 
     traceback.print_exc() # no error should pass silently 
2

您使用pytest-2.5.1吗? pytest-2.5,特别是issue287应该支持运行所有终结器,并重新提出第一个失败的异常(如果有的话)。

+0

谢谢,那正是我需要的。看起来像我需要更新我的pytest。再次感谢 – user3205834

+0

如果此答案确实回答您的问题,也许您可​​以通过单击绿色复选标记接受它?不仅如此,它会为你赢得一些声誉。 –