gpt4 book ai didi

python - 如何解决“PytestDeprecationWarning : pytest. config global is deprecated

转载 作者:太空宇宙 更新时间:2023-11-04 04:20:56 26 4
gpt4 key购买 nike

我正在测试一个名为- https://huew.co 的网站

为此,我正在开发我的框架。在 utils/create_driver 中,我编写了我的代码,它将通过用户输入打开浏览器,就像用户在终端中输入“chrome”和 env=local

示例:python -m pytest test/test_infilect.py --type=chrome --env=local 然后 chrome 浏览器应该初始化并打开提供的 url。

但我收到错误-UnboundLocalError:赋值前引用了局部变量'driver'

和警告:PytestDeprecationWarning:pytest.config 全局已弃用。请使用 request.configpytest_configure(如果你e 一个 pytest 插件)代替。 url = pytest.config.option.env.lower()

PytestDeprecationWarning:pytest.config 全局已弃用。请使用 request.configpytest_configure(如果你e 一个 pytest 插件)代替。 browser_info = pytest.config.option.env.lower()

帮助解决同样的问题。

from selenium.webdriver import Chrome,Firefox,Ie
import pytest

# @pytest.fixture
def get_browser_instance():

browser_info = pytest.config.option.env.lower()

url = pytest.config.option.env.lower()

if browser_info == 'chrome':
driver = Chrome('./browser_exe/chromedriver.exe')

elif browser_info == 'firefox':
driver = Firefox('./browser_exe/geckodriver.exe')

elif browser_info == 'ie':
driver = Ie('./browser_exe/IEDriverServer.exe')

driver.maximize_window()
driver.implicitly_wait(60)

if url == 'local':
driver.get('https://huew.co/')

return driver

当我从 pycharms 终端输入命令时,测试应该运行 -python -m pytest test/test_infilect.py --type=chrome --env=local

最佳答案

只需将 request 作为参数传递给您的 fixture,并将您的 fixture 主体中对 pytest.config 的引用替换为 request.config

关于python - 如何解决“PytestDeprecationWarning : pytest. config global is deprecated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54496303/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com