So I have been trying to get pytest to run selenium tests on different environments based on some command-line argument. But it keeps throwing this error:
TypeError: setup_class() takes exactly 2 arguments (1 given)
It seems that it is understanding that setup_class
takes 2 arguments, but host
is not being passed. Here's the code for setup_class
:
def setup_class(cls, host):
cls.host = host
And here is the conftest.py file:
def pytest_addoption(parser):
parser.addoption("--host", action="store", default='local',
help="specify the host to run tests with. local|stage")
@pytest.fixture(scope='class')
def host(request):
return request.config.option.host
What is strange is that host
is being seen by the functions (so if I make a test_function and pass host as a parameter, it gets it just fine), it is just the setup
fixtures that are not working.
I looked around and found this, pytest - use funcargs inside setup_module but that doesn't seem to be working (and it is outdated since 2.3.
Does anyone know what I'm doing wrong? Using py.test 2.3.2.
Thanks