我正在使用pytest-mozwebqa
插件来运行一些selenium测试。我想只针对所有测试登录应用程序一次,所以我尝试在conftest.py
中使用会话范围的夹具,但是我收到了以下错误。如何编写此登录fixture,以便每次测试都不需要登录,并且所有测试都可以使用单个登录?
这是我得到的错误:
================================================================================================= 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)
conftest.py
的内容:
@pytest.fixture(scope='session')
def login(mozwebqa, variables):
data_page = DataPage(mozwebqa)
network_page = data_page.select_version(variables)
return network_page
答案 0 :(得分:1)
你需要制作登录功能范围,与mozwebqa fixture
相同答案 1 :(得分:0)
k4nar 发布了此解决方法 on the github issue for the bug,对我来说效果很好。
<块引用>@pytest.fixture(scope=session)
def my_fixture(request):
capmanager = request.config.pluginmanager.getplugin("capturemanager")
...
with capmanager.global_and_fixture_disabled():
print_something()
...