current code:
conftest.py
@pytest.fixture(scope="class")
def setup_portal(request): ### NOTE: I want this to be: def setup_portal(request,login=False)
"@pytest.mark.usefixtures" : applied to the class == a fixture to every test methods in the class.
Since the fixture "setup_portal" has a scope == "class" -> webdriver will be initialized only once per each class."""
# setup chrome driver ...
## login into portal
# TODO:
## if login: # login
request.cls.driver = chrome_driver
yield chrome_driver
chrome_driver.close()
test_file.py
@pytest.mark.usefixtures("setup_portal") ### initialize driver
class TestMusimotionPage:
... do stuff
The goal: request setup_portal fixture with a parameter: login == True and then login
One solution for a similar problem is to define "setup_portal" as a method in the fixture as shown here: Can I pass arguments to pytest fixtures?
The issue: the fixture is being called using:
@pytest.mark.usefixtures("setup_portal")
so I cannot pass an argument as such:
conftest.py
@pytest.fixture(scope="class")
def setup_portal():
def _setup_portal(request, login=False):
"@pytest.mark.usefixtures" : applied to the class == a fixture to every test methods in the class.
Since the fixture "setup_portal" has a scope == "class" -> webdriver will be initialized only once per each class."""
# setup chrome driver ...
## login into portal
if login:
## login...
request.cls.driver = chrome_driver
yield chrome_driver
chrome_driver.close()
return _setup_portal()
test_file.py
@pytest.mark.usefixtures("setup_portal") ### not sure how to pass : login == True
class TestMusimotionPage:
setup_portal(login==True). ## doesn't work
... do stuff
what do?