i am testing in pytest. here is my code
def pytest_addoption(parser):
parser.addoption('--uid')
@pytest.fixture
def login_id(request,pytestconfig):
user_id = pytestconfig.getoption('--uid')
return user_id
what it does is take the cli argument in pytest
@pytest.fixture
def func():
login(login_id)
return session()
when i am performing the test on a module which require the session to be created login_id is giving me data as
< function login_id at 0x00000000092F79D8>
i am unable to get this data , how to get the value which i am passing in cli argument.
i am using pycharm, python3.5 .
cli parameter as --uid username
i am not getting the username in login
fucntion but instead getting the location of data.
thanks and regards
If you want to use a fixture's value in another fixture, just pass it as a parameter:
@pytest.fixture
def login_id(request):
...
return ...
@pytest.fixture
def func(login_id):
login(login_id)
return session()
Suggestion aside: you don't need the pytestconfig
fixture since you are already using request
. You can get the config via request.config
in the login_id
fixture:
@pytest.fixture
def login_id(request):
user_id = request.config.getoption('--uid')
return user_id
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.