如何使用xdist运行pytest-selenium并使用cli arg驱动程序?

时间:2019-11-19 21:36:26

标签: selenium docker pytest xdist pytest-selenium

我正在尝试使用xdist并行运行多个测试,并根据用户的命令行参数(例如)确定webdriver  --driver远程/ Chrome / etc

最终,我正在尝试将其扔到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)

如果尝试从安装程序夹具中删除范围,则会从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集合的情况下,此方法以前可以正常工作。如果可能的话,我该怎么做?我在做什么错了?

0 个答案:

没有答案