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)
運(yùn)行
pytest -s -v ./test_project
或 main 運(yùn)行
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)文章
對tensorflow 的模型保存和調(diào)用實(shí)例講解
今天小編就為大家分享一篇對tensorflow 的模型保存和調(diào)用實(shí)例講解,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-07-07Python filter過濾器原理及實(shí)例應(yīng)用
這篇文章主要介紹了Python filter過濾器原理及實(shí)例應(yīng)用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08Python 中 Virtualenv 和 pip 的簡單用法詳解
本篇文章主要介紹了Python 中 Virtualenv 和 pip 的簡單用法詳解,具有一定的參考價(jià)值,有興趣的可以了解一下2017-08-08在python中將字符串轉(zhuǎn)為json對象并取值的方法
今天小編就為大家分享一篇在python中將字符串轉(zhuǎn)為json對象并取值的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12