pytest中conftest.py使用小结
更新时间:2023年09月18日 09:07:03 作者:Rsingstarzengjx
conftest.py文件是Pytest框架里面一个很重要的东西,本文主要介绍了pytest中conftest.py使用小结,具有一定的参考价值,感兴趣的可以了解一下
创建test_project 目录
test_project/sub/test_sub.py
def test_baidu(test_url):
print(f'sub ={test_url}')test_project/conftest.py 设置钩子函数 只对当前目录 和子目录起作用
import pytest
#设置测试钩子函数
@pytest.fixture()
def test_url():
return "https://www.baidu.com"test_project/test_demo.py

def test_baidu(test_url):
print(test_url)运行
pytest -s -v ./test_project
或 main 运行
import pytest
if __name__=='__main__':
#pytest.main(['-s','./fixture'])
#pytest.main(['-v', './fixture','--junit-xml=./report/log.xml'])
#pytest.main(['-v', './fixture', '--pastebin=all'])
pytest.main(['-v','-s' ,'./test_project', '--pastebin=all'])plugins: anyio-3.5.0 collecting ... collected 2 items test_project/test_demo.py::test_baidu https://www.baidu.com PASSED test_project/sub/test_sub.py::test_baidu sub =https://www.baidu.com PASSED ============================== 2 passed in 0.05s ============================== ==================== Sending information to Paste Service ===================== pastebin session-log: https://bpa.st/show/H4UQ
到此这篇关于pytest中conftest.py使用小结的文章就介绍到这了,更多相关pytest conftest.py使用内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
python使用openpyxl库读写Excel表格的方法(增删改查操作)
这篇文章主要介绍了python使用openpyxl库读写Excel表格的方法(增删改查操作),本文通过实例图文相结合给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2021-05-05
python GUI库图形界面开发之PyQt5打印控件QPrinter详细使用方法与实例
这篇文章主要介绍了python GUI库图形界面开发之PyQt5打印控件QPrinter详细使用方法与实例,需要的朋友可以参考下2020-02-02


最新评论