2016-03-07 48 views
-1

對於我的測試,我構建了臨時文件,我希望刪除測試結果(失敗或測試通過)。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

回答

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. 
    ... 
相關問題