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 基于Twisted框架的文件夾網(wǎng)絡(luò)傳輸源碼
這篇文章主要介紹了Python 基于Twisted框架的文件夾網(wǎng)絡(luò)傳輸源碼,需要的朋友可以參考下2016-08-08
python使用openpyxl庫讀寫Excel表格的方法(增刪改查操作)
這篇文章主要介紹了python使用openpyxl庫讀寫Excel表格的方法(增刪改查操作),本文通過實例圖文相結(jié)合給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-05-05
python GUI庫圖形界面開發(fā)之PyQt5打印控件QPrinter詳細(xì)使用方法與實例
這篇文章主要介紹了python GUI庫圖形界面開發(fā)之PyQt5打印控件QPrinter詳細(xì)使用方法與實例,需要的朋友可以參考下2020-02-02
如何在Django中設(shè)置定時任務(wù)的方法示例
這篇文章主要介紹了如何在Django中設(shè)置定時任務(wù)的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-01-01
在服務(wù)器上安裝python3.8.2環(huán)境的教程詳解
這篇文章主要介紹了在服務(wù)器上安裝python3.8.2環(huán)境的教程詳解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-04-04
Python教程通過公共鍵對不同字典進(jìn)行排序示例詳解
本篇文章是Python教程基礎(chǔ)篇,通過一些示例為大家講解Python通過公共鍵對不同字典進(jìn)行排序的方式,有需要的朋友可以借鑒參考下,希望能夠有所幫助2021-09-09

