Reputation: 101
I want to pass argument to the my test using py.Test.
Note : This argument will be global across test. Please suggest how to do that.
Upvotes: 2
Views: 5126
Reputation: 2362
Check this manaual. You should define your argument by using parser.addoption
method in hook pytest_addoption
, at file conftest.py
. Then you can get value of your argument by checking request.config.getoption
method:
# /home/user/conftest.py
def pytest_addoption(parser):
parser.addoption('--stringvalue', action='store', dest='stringvalue')
# /home/user/test_first.py
def test_test1(request):
assert 'checkme' == request.config.getoption('stringvalue')
$ py.test /home/user/test_first.py --stringvalue checkme
Upvotes: 9