0

I want to make a test in pytest and I am also using pytest-bdd. The idea is I have an id and from this id, I calculate a destination. But in the next steps, this destination may change, it can be a broadcast or to a specific group or an individual. That's why I wanted to create fixtures for them. But also these functions are given/when/then functions. When I use both it gives an error saying request doesn't have attribute param.

scenarios('../features/set_settings.feature')

@pytest.fixture(scope='module')
def session():
    appium_service = AppiumService()
    appium_service.start()

    # Return to the tests
    yield

    # After all tests in the class are executed, free the resources
    appium_service.stop()

@pytest.fixture(scope='module')
def driver(session):
    capabilities = dict(
        platformName=APPIUM_PLATFORM,
        automationName=APPIUM_AUTOMATION,
        deviceName=APPIUM_DEVICE_NAME,
        udid=APPIUM_UDID,
        noReset=True,
        appPackage=APPIUM_APP_PACKAGE,
        appActivity=APPIUM_APP_ACTIVITY
    )
    driver = webdriver.Remote(SERVER_URL_BASE, options=UiAutomator2Options().load_capabilities(caps=capabilities))

    for context in driver.contexts:
        if 'webview' in str(context).lower():
            driver.switch_to.context(context)  # Switch to WebView in order to run JavaScript scripts
            break
    # Return the driver to the tests
    yield driver

    # After all tests in the class are executed, free the resources
    driver.quit()

# Returns the destination address for groups
@pytest.fixture(scope="function")
def destination_group(request):
    group_id = request.param
    return group_id ^ CAST_GROUP  # A constant to change destination to a group from group id


# Given Steps
@given(parsers.parse("The initial {mode} is {level:n}"))
@pytest.mark.parametrize("destination_group", [GROUP_ID], indirect=True)
def set_initial_level(driver, destination_group, mode, level):
    set_setting_through_app(f"set_{light_mode}", level, DESTINATION, driver)
    time.sleep(1)

So here set_setting_through_app() takes the setting, the level destination and driver that is going to execute this. It works without a problem because when only @given(parsers.parse("The initial {mode} is {level:n})) exists it gives no error and passes the test. Also works as well. But when I add parametrize part before or after it gives an error saying "AttributeError: 'SubRequest' object has no attribute 'param'". Is there a way to make this work at the same time?

0 Answers0