Below is the Server.py file
class Server():
def __init__(self, certral=None, user=None, password=None):
cwd = os.path.dirname(__file__)
self.propPath = cwd + "/../server-profiles.json"
print(os.path.normpath(self.propPath))
with open(os.path.normpath(self.propPath)) as data_file:
data = json.load(data_file)
self.propertyDataJson = data
self.testcategory = data['generic']['category']
Below is the conftest.py file.
def pytest_addoption(parser):
parser.addoption(
"--stack", action="store", default="sanity", help="my option: sanity or qa"
)
@pytest.fixture
def cmdopt(request):
return request.config.getoption("--stack")
Now, I want the user to give input pytest xyz.py --stack=sanity and the value should be stored in self.testcategory, for ex: self.testcategory = sanity or self.testcategory = qa under Server() class in Server.py file.