11
votes

I am using pytest-mozwebqa plugin for running some selenium tests. I want to login to the application only once for all the tests so I tried using a session scoped fixture in the conftest.py but I am getting following error. How can I write this login fixture so that login is not required per test and a single login is available to all tests?

This is the error I am getting:

================================================================================================= ERRORS ==================================================================================================
___________________________________________________________________________ ERROR at setup of TestData.test_selected_version ____________________________________________________________________________
ScopeMismatch: You tried to access the 'function' scoped fixture 'mozwebqa' with a 'module' scoped request object, involved factories
conftest.py:6:  def login(mozwebqa, variables)
../../.virtualenvs/webqa/lib/python2.7/site-packages/pytest_mozwebqa/pytest_mozwebqa.py:159:  def pytest_funcarg__mozwebqa(request)

Content of the conftest.py:

@pytest.fixture(scope='session')
def login(mozwebqa, variables):
    data_page = DataPage(mozwebqa)
    network_page = data_page.select_version(variables)
    return network_page
2

2 Answers

4
votes

you need to make the login function scope, same as the mozwebqa fixture

0
votes

k4nar posted this workaround on the github issue for the bug, and it’s working fine for me.

@pytest.fixture(scope=session)
def my_fixture(request):
    capmanager = request.config.pluginmanager.getplugin("capturemanager")

    ...

    with capmanager.global_and_fixture_disabled():
        print_something()

    ...