bl双性强迫侵犯h_国产在线观看人成激情视频_蜜芽188_被诱拐的少孩全彩啪啪漫画

如何在Pytest中使用mark-創新互聯

如何在Pytest中使用mark?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。

成都創新互聯是一家集網站建設,塔城企業網站建設,塔城品牌網站建設,網站定制,塔城網站建設報價,網絡營銷,網絡優化,塔城網站推廣為一體的創新建站企業,幫助傳統企業提升企業形象加強企業競爭力??沙浞譂M足這一群體相比中小企業更為豐富、高端、多元的互聯網需求。同時我們時刻保持專業、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學習、思考、沉淀、凈化自己,讓我們為更多的企業打造出實用型網站。

使用方法:

1、注冊標簽名

2、在測試用例/測試類前面加上:@pytest.mark.標簽名

打標記范圍:測試用例、測試類、模塊文件

注冊方式:

1、單個標簽:

在conftest.py添加如下代碼:

def pytest_configure(config):
  # demo是標簽名
  config.addinivalue_line("markers", "demo:示例運行")

2、多個標簽:

在conftest.py添加如下代碼:

def pytest_configure(config):
  marker_list = ["testdemo", "demo", "smoke"] # 標簽名集合
  for markers in marker_list:
    config.addinivalue_line("markers", markers)

3、添加pytest.ini 配置文件(在你項目的任意一個文件下,新建一個file,文件命名為pytest.ini)

[pytest]
markers=
  smoke:this is a smoke tag
  demo:demo
  testdemo:testdemo

使用方法:

import pytest


@pytest.mark.testdemo
def test_demo01():
  print("函數級別的test_demo01")


@pytest.mark.smoke
def test_demo02():
  print("函數級別的test_demo02")


@pytest.mark.demo
class TestDemo:
  def test_demo01(self):
    print("test_demo01")

  def test_demo02(self):
    print("test_demo02")

運行方式:

1、命令行模式

通過標記表達式執行
pytest -m demo
這條命令會執行被裝飾器@pytest.mark.demo裝飾的所有測試用例

生成html報告:
pytest -m demo --html=Report/report.html

生成xml報告:
pytest -m demo --junitxml=Report/report.xml

運行指定模塊:
pytest -m demo --html=Report/report.html TestCases/test_pytest.py

運行指定測試目錄
pytest -m demo --html=Report/report.html TestCases/

通過節點id來運行:
pytest TestCases/test_pytest.py::TestDemo::test_demo01

通過關鍵字表達式過濾執行
pytest -k "MyClass and not method"
這條命令會匹配文件名、類名、方法名匹配表達式的用例

獲取用例執行性能數據
獲取最慢的10個用例的執行耗時
pytest --durations=10

2、新建run.py文件運行,代碼如下:

pytest.main(["-m","demo","--html=Report/report.html"])

看完上述內容,你們掌握如何在Pytest中使用mark的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注創新互聯行業資訊頻道,感謝各位的閱讀!

文章標題:如何在Pytest中使用mark-創新互聯
文章地址:http://vcdvsql.cn/article12/dcppgc.html

成都網站建設公司_創新互聯,為您提供關鍵詞優化、小程序開發、微信公眾號、品牌網站制作定制開發、網站導航

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都定制網站網頁設計