1 year ago

#71376

test-img

Edgar L

Is it possible to pass a flag or argument dynamically to pytest fixtures?

I would like to do an optimization doing something like this.

example:

usually my tests do something like this:

launch test command > flash desired build > do the test > teardown

I would like to read device values before to flash to skip it when it is not necessary

for debugging purposes I usually use: pytest tests/mytest.py --skip-device-flash and this will run the test without flashing the device, but I would like to find a way to send that flag --skip-device-flash when I determined the device is already flash and it is not necessary to do it again

so the path would be something like this:

launch test command > read device values  > do the tests > teardown()
                     if device is not set:
                        flash the device
                     else:
                         return --skip-device-flash
                         factory_reset()

the fixture in charge to set the device is

@pytest.fixture(scope='module') 
def flashed_device(adb_cleanup, boot_completed_device, request):
    device = boot_complete_device

boot_complete_device is another fixture that calls another fixture to flash the device. When I issue the command sending the --skip-device-flash flag it is being sent through request and it can be read by

request.config.getoption('--skip-device-flash')

so what I'm looking for is the way to send the --skip-device-flash value after issued the command through the request which is shared across all the fixtures by the time I call flashed_device(), something like request.config.setoption, is it possible?

request

pytest

fixtures

0 Answers

Your Answer

Accepted video resources