我在 DB 中插入資料,并使用行 ID 對正在測驗的端點進行 API 呼叫。我有一個多次運行固定裝置的引數化測驗。
@pytest.mark.parametrize(
"endpoint",
[
"/github/access-form",
"/github/issue-form",
],
)
def test_marketplace_details(
client: TestClient, session: Session, endpoint: str, add_marketplace_product_materio_ts: MarketplaceProductLink
):
# here I want to know the id of inserted record. I guess I can get it from the count of fixture "add_marketplace_product_materio_ts" run
r = client.get(f"{endpoint}?marketplace=1")
assert r.status_code == 200
data = r.json()
assert data["marketplaces"] == IsList(
IsPartialDict(
name="themeselection",
purchase_verification_url="https://google.com",
)
)
assert data["brands"] == []
assert data["product_w_technology_name"] == []
因此,如何獲得在測驗中運行的夾具計數,以便將正確的 id 傳遞給r = client.get(f"{endpoint}?marketplace=1"). marketplace=1這里1應該是夾具運行的計數。
謝謝。
uj5u.com熱心網友回復:
您可以使用列舉:
@pytest.mark.parametrize("idx, endpoint", enumerate(["zero", "one"]))
def test_marketplace_details(idx, endpoint):
print(idx, endpoint)
# prints:
# 0 zero
# 1 one
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/455834.html
上一篇:HowcanIselectitemfromdropdown,whenoption'selementnotinteractableviaselenium/python?
下一篇:使用“@”匯入進行笑話測驗
