当前位置:首页 > 编程笔记 > 正文
已解决

【pytest】conftest.py使用

来自网友在路上 156856提问 提问时间:2023-09-19 11:02:23阅读次数: 56

最佳答案 问答题库568位专家为你答疑解惑

1. 创建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 pytestif __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 itemstest_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

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"【pytest】conftest.py使用":http://eshow365.cn/6-9282-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!