比方說,我有一個參數化夾具這樣的:如何在Pytest中使用夾具的覆蓋參數?
@pytest.fixture(params=[1, 2, 800]):
def resource(request):
return Resource(capacity=request.param)
當我使用夾具作爲測試功能參數,Pytest運行與所有三個版本的測試:
def test_resource(resource): # Runs for capacities 1, 2, and 800.
assert resource.is_okay()
然而,一些測試中,我想改變該燈具被內置的參數:
def test_worker(resource, worker): # Please run this for capacities 1 and 5.
worker.use(resource)
assert worker.is_okay()
我怎麼可以指定只接受SPECI的某些版本fied夾具?
'indirect = True'位似乎是pytest中記錄不完整的寶石之一!謝謝,這正是我需要的! –