Parametrize a test with a list from a fixture? #10571
-
Here's my fixture: @fixture
def devices(scope='module');
with connect(get_all_devices()) as connected_devices:
yield connected_devices Here's how I want to use it: @parametrize('device', devices)
def test_routine(device):
device.do_something()
assert device.is_ok() What I'm doing instead: def test_routine(subtests, devices):
for index, device in enumerate(devices):
with subtests.test(device, i=index):
device.do_something()
assert device.is_ok() Is there any way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
no, fixtures happen after parametrize currently there is no plan/effort to enable a parametrize scope for them |
Beta Was this translation helpful? Give feedback.
-
You can probably get to a similar result with a custom marker and |
Beta Was this translation helpful? Give feedback.
-
This is how I would do: @fixture(scope='module', params=devices)
def device(request):
with connect(request.param) as device:
yield connected_device
def test_routine(device):
device.do_something()
assert device.is_ok()` Note this will fail if the way you collect If you do not want the testing process to crash during the collection process or prefer some more explicit names for each of the fixture parametrization, you should resolve/test the driver on the fixture runtime: @fixture(scope='module', params=["driver_string1", "driver_string2"])
def device(request):
device_driver = driver_from_string(request.param)
with connect(request.param) as device:
device.verify_something_before_test()
yield connected_device Here I add also an example from my packages: |
Beta Was this translation helpful? Give feedback.
no, fixtures happen after parametrize
currently there is no plan/effort to enable a parametrize scope for them