我正在尝试使用 xdist 并行运行多个测试,并根据用户的命令行参数(例如 --driver Remote/Chrome/etc)确定 webdriver
最终,我试图把它扔到 docker 中,以便它可以在 gitlab 管道中使用。
这是我尝试过的..
conftest.py
@pytest.fixture(scope="session")
def setup(request, selenium):
# Get cli specified driver
driver = selenium
driver.get(os.environ.get('server'))
# Collection
session = request.node
for item in session.items:
cls = item.getparent(pytest.Class)
setattr(cls.obj, "driver", driver)
# Teardown when tests finish
yield driver
driver.close()
test_login.py
@pytest.mark.usefixtures("setup")
class Test:
def test_loginValid(self, selenium):
util.loginEnv(selenium)
这给了我错误..
========================================================================= ERRORS =========================================================================
_________________________________________________________ ERROR at setup of Test.test_loginValid _________________________________________________________ ScopeMismatch: You tried to access the 'function' scoped fixture 'selenium' with a 'session' scoped request object, involved factories
tests\conftest.py:37: def setup(request, selenium)
..\appdata\local\programs\python\python37-32\lib\site-packages\pytest_selenium\pytest_selenium.py:205: def selenium(driver)
如果我尝试从 setup 夹具中删除范围,我会从 conftest.py 收到以下错误
# Collection
session = request.node
> for item in session.items:
E AttributeError: 'Function' object has no attribute 'items'
tests\conftest.py:59: AttributeError
-------------------------------------------------------------------- pytest-selenium --------------------------------------------
Driver log: ...\pytest-426\test_loginValid0\driver.log
URL: *** CENSORED ***
WARNING: Failed to gather log types: Message: unknown command: Cannot call non W3C standard command while in W3C mode
以前在没有 xdist 集合的情况下执行此方法。如果可能的话,我该如何完成这项工作,我做错了什么?