2017-10-08 27 views
1

我試着評估下面的代碼,但是夾具方法'newFix'甚至沒有被評估,所以控制檯在我嘗試執行時沒有打印'This is executed'以下命令Pytest在一個類裏面的燈具沒有執行

pytest -v --capture =無

但是測試1和TEST2都返回通。它應該在每次測試之前打印出「這是執行的」。但是,如果我刪除類行,並使函數通用,那麼將執行fixture方法'newFix'。任何想法爲什麼它不在課堂上執行?請指教。

import pytest 

class TestClass: 

    @pytest.fixture() 
    def newFix(): 
     print('This is executed') 

    def test_Test1(newFix): 
     assert True 

    def test_Test2(newFix): 
     assert True 
+0

看看該文檔https://docs.pytest.org/en/latest/fixture.html #使用-夾具-從類模塊-或項目 – slackmart

回答

1

的測試非靜態方法,因此他們應該被定義爲

def test_Test1(self, newFix): 
    # Unit test here