ScopeMismatch使用会话范围的fixture与pytest的pytest-mozwebqa插件

Ami*_*mit 7 python fixtures pytest

我正在使用pytest-mozwebqa插件运行一些硒测试.我想只为所有测试登录一次应用程序,所以我尝试使用会话范围的夹具conftest.py但是我收到了以下错误.如何编写此登录夹具,以便每次测试不需要登录,并且所有测试都可以使用单个登录?

这是我得到的错误:

================================================================================================= 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)
Run Code Online (Sandbox Code Playgroud)

内容conftest.py:

@pytest.fixture(scope='session')
def login(mozwebqa, variables):
    data_page = DataPage(mozwebqa)
    network_page = data_page.select_version(variables)
    return network_page
Run Code Online (Sandbox Code Playgroud)

小智 4

您需要设置登录功能范围,与 mozwebqa 固定装置相同

  • 谢谢!如果我将登录保留为函数范围,它就会起作用。但是,这会使每个测试都运行登录。我只想在所有测试开始时运行登录一次,并继续使用同一会话。我有办法实现这一目标吗? (7认同)