I got to know how to pass command line parameters in pytest. I want to print or do some basic validation in my setup_class() or setup_module() against the variables passed as command line arguments.
I am able to access these variables in test methods but not in setup_class or setup_module. Is this even possible?
I want to do something like this...
conftest.py
def pytest_addoption(parser):
parser.addoption('--user',action='store', help='email id Ex: abc@infoblox.com')
test_1.py
import pytest
def setup_module():
print 'Setup Module'
def teardown_module():
print "Teardown Module"
class Test_ABC:
def setup_class(cls,request):
user = request.config.option.user
print user
print 'Setup Class'
def teardown_class(cls,request):
print 'Teardown Class'
def test_12(self,request):
print "Test_12"
assert 1==1