Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何解决;PytestDeprecationWarning:pytest.config全局已弃用_Python_Python 3.x_Selenium_Selenium Webdriver_Pytest - Fatal编程技术网

Python 如何解决;PytestDeprecationWarning:pytest.config全局已弃用

Python 如何解决;PytestDeprecationWarning:pytest.config全局已弃用,python,python-3.x,selenium,selenium-webdriver,pytest,Python,Python 3.x,Selenium,Selenium Webdriver,Pytest,我正在测试一个名为- 为此,我正在开发我的框架。 在utils/create_驱动程序中,我编写了我的代码,它将通过用户输入打开浏览器,就像用户在终端中输入'chrome',env=local一样 示例:python-m pytest/test_infict.py--type=chrome--env=local 然后chrome浏览器应该初始化并打开提供的url 但我犯了一个错误- 取消绑定LocalError:分配前引用的局部变量“driver” 和警告: PytestDeprecationW

我正在测试一个名为-

为此,我正在开发我的框架。 在utils/create_驱动程序中,我编写了我的代码,它将通过用户输入打开浏览器,就像用户在终端中输入'chrome',env=local一样

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

但我犯了一个错误- 取消绑定LocalError:分配前引用的局部变量“driver”

和警告: PytestDeprecationWarning:pytest.config的
global已被弃用。请使用
request.config
pytest\u configure
(如果您需要 而不是一个pytest插件)。 url=pytest.config.option.env.lower()

PytestDeprecationWarning:pytest.config的
global已被弃用。请使用
request.config
pytest\u configure
(如果您需要 而不是一个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_infict.py--type=chrome--env=local

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

您的主要问题不是警告(正如q标题所说的),它只是一个去润滑警告;这里的问题是
驱动程序的UnboundLocalError异常-这意味着您引用了一个未创建的变量。这意味着if/else开关在不匹配任何选项的情况下可以通过。检查
browser\u info
的值-它是否与您正在检查的3个值中的任何一个匹配。我已检查。driver=Chrome('./browser_exe/chromedriver.exe'),Chrome驱动程序的相对路径。但是错误仍然在发生。嗯,仔细查看源代码,这对我来说是有问题的-您正在将
driver
url
设置为相同的值-
pytest.config.option.env
。在你要检查的夹具的末尾,该值是否等于“local”-以打开你说要测试的站点;同时,你希望它的值是“chrome”、“Firefox”或“ie”中的一个来打开浏览器。不推荐警告绝对是一个问题,尽管无可否认不是本例中的主要问题。要解决此警告(从而避免将来损坏),请参阅。