pytest中conftest.py使用小結(jié)
創(chuàng)建test_project 目錄
test_project/sub/test_sub.py
def test_baidu(test_url):
print(f'sub ={test_url}')test_project/conftest.py 設(shè)置鉤子函數(shù) 只對當(dāng)前目錄 和子目錄起作用
import pytest
#設(shè)置測試鉤子函數(shù)
@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
到此這篇關(guān)于pytest中conftest.py使用小結(jié)的文章就介紹到這了,更多相關(guān)pytest conftest.py使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于Python實現(xiàn)優(yōu)雅的目錄結(jié)構(gòu)打印工具
在軟件開發(fā),系統(tǒng)管理和日常工作中,我們經(jīng)常需要查看和分析目錄結(jié)構(gòu),本文我們將使用Python語言打造一個目錄結(jié)構(gòu)打印工具,有需要的小伙伴可以了解下2025-07-07
Python使用django搭建web開發(fā)環(huán)境
這篇文章主要為大家詳細(xì)介紹了Python使用django搭建web開發(fā)環(huán)境,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06
Python設(shè)計模式中的結(jié)構(gòu)型適配器模式
這篇文章主要介紹了Python設(shè)計中的結(jié)構(gòu)型適配器模式,適配器模式即Adapter?Pattern,將一個類的接口轉(zhuǎn)換成為客戶希望的另外一個接口,下文內(nèi)容具有一定的參考價值,需要的小伙伴可以參考一下2022-02-02
對Python2與Python3中__bool__方法的差異詳解
今天小編就為大家分享一篇對Python2與Python3中__bool__方法的差異詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-11-11

