pytest。执行所有拆卸模块

时间:2014-01-17 09:09:34

标签: python pytest

我在测试中使用了funcargs:

def test_name(fooarg1, fooarg2):

所有这些工厂都有pytest_funcarg__工厂,它返回request.cached_setup,所以它们都有设置/拆卸部分。

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

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

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分: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
相关问题