-1

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.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
RR HS
  • 3
  • 3

1 Answers1

0

I am not sure what you are trying to accomplish with this but if I have to guess:

I think this can only be done if you create a server fixture:

@pytest.fixture
def server(cmdopt):
    server_ = Server()
    server_.testcategory = cmdopt
    yield server_

Or if that is not an option for you just add the flag in the test function.

dosas
  • 567
  • 4
  • 18