py.test:在测试后执行某些操作

问题描述:

对于我的测试,我构建了临时文件,我希望删除测试结果(失败或测试通过)。py.test:在测试后执行某些操作

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

+1

http://pytest.org/latest/xunit_setup.html –

+0

感谢您指点我。看起来[这个链接](http://pytest.org/latest/fixture.html#fixture-finalization-executing-teardown-code)更具有说服力。如果管理员想要关闭我的问题,他会做。 – projetmbc

这是在官方文档中找到的画布。

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. 
    ...