py.test:在测试后做一些事情

时间:2016-03-07 14:53:48

标签: python-3.x pytest

对于我的测试,我构建临时文件,我想删除测试结果(失败或测试通过)。

有没有办法在完成测试我的Python文件之后“告诉”py.test做某事?

1 个答案:

答案 0 :(得分:0)

这是官方文档中的画布。

from pytest import fixture

@fixture(scope="module")
def or_datas(request):
    # Something done before a test.

    def fin():
        # Here, just do something after the test.
        ...

    request.addfinalizer(fin)


# How to use it ?

def test_something(or_datas):
    # Note the argument corresponding the function decorated
    # by fixture.
    ...