[英]How to run fixture before mark.parametrize
Sample_test.py
@pytest.mark.parametrize(argnames="key",argvalues=ExcelUtils.getinputrows(__name__),scope="session")
def test_execute():
#Do something
conftest.py
@pytest.fixture(name='setup',autouse=True,scope="session")
def setup_test(pytestconfig):
dict['environment']="QA"
如上面的代碼所示,我需要在 test_execute 方法之前運行 setup 夾具,因為 getinputrows 方法需要環境來讀取工作表。 不幸的是,參數化夾具在 setup_test 之前執行。 有什么辦法可以嗎?
需要在測試function里面執行參數,而不是在裝飾器里面:
@pytest.mark.parametrize("key", [ExcelUtils.getinputrows], scope="session")
def test_execute(key):
key(__name__)
#Do something
或事先將__name__
綁定到 function 調用,但同樣,在測試中調用 function :
@pytest.mark.parametrize("key", [lambda: ExcelUtils.getinputrows(__name__)], scope="session")
def test_execute(key):
key()
#Do something
請注意,我並不完全理解您在做什么,因此這些示例可能有意義,也可能沒有意義。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.