pytest.ini获取base_url时报错问题

在pytest.ini文件里添加base_url,测试代码调用base_url报错:

Skipped: This test is destructive and the target URL is considered a sensitive environment. If this test is not destructive, add the 'nondestructive' marker to it

只要pytest.ini里定义base_url,即使不引用运行也会报错。

网上搜了很久没找到解决方案,遂记录下来以便后面有人遇到参考。

后来自己将依赖的插件挨个卸载重装,当卸载掉pytest-selenium插件后恢复正常。

原因:未知,也并不知道什么时候安装的,先卸载了。

查了查相关知识点:

Pytest-selenium是Pytest的一个插件, 安装方法:

pip3 install pytest pytest-selenium

用例编写时只需要在测试函数中传入selenium参数作为driver使用即可, 如下:

# test_baidu.py

def test_baidu(selenium):

selenium.get("https://www.linuxidc.com")  # selenium即driver

然后在运行时指定通过--driver指定浏览器即可:

pytest test_baidu.py --driver Chrome

需要提前配置好selenium环境及chromedriver



本文来源:码农网
本文链接:https://www.codercto.com/a/84421.html
原文地址:https://www.cnblogs.com/little-monica/p/15214388.html