I know that there is a way to pass args in tests itself like it was shown here, but is there a way to pass in conftest.py directly? I want to configure some common stuff for all tests this way. This is my conftest.py:
import pytest
from appium import webdriver
import json
import os
from config import *
CAPS_FILE = "android_9.0_emulator.json"
def pytest_addoption(parser):
parser.addoption("--desired-capabilities", action="store", default=CAPS_FILE)
def pytest_generate_tests(metafunc):
# This is called for every test. Only get/set command line arguments
# if the argument is specified in the list of test "fixturenames".
option_value = metafunc.config.option.name
if 'desired-capabilities' in metafunc.fixturenames and option_value is not None:
# metafunc.parametrize("desired_capabilities", [option_value])
CAPS_FILE = option_value
def get_desired_caps(json_file):
with open(desired_caps_dir_path) as json_file:
return json.load(json_file)
@pytest.fixture(scope="session")
def browser():
driver = webdriver.Remote(appium_driver_url, desired_capabilities=get_desired_caps(CAPS_FILE))
# driver = webdriver.Remote(appium_driver_url, desired_capabilities=get_desired_caps(metafunc.config.option))
yield driver
driver.quit()
UPDATE: or maybe I should use this function to initialize/configure conftest.py itself from command line:
def pytest_configure(config):
option_val = config.option.name
if 'desired-capabilities' in config.option and option_val is not None:
CAPS_FILE = option_val
Or maybe there is a better approach?