【pytest學習】setup、teardown、重復執行、不執行等方法的使用


一、setup、teardown

  • 模塊級別:setup_module、teardown_module
  • 函數級別:setup_function、teardown_function,不在類中的方法
  • 類級別:setup_class、teardown_class
  • 方法級別:setup_method、teardown_method
  • 方法細化級別:setup、teardown

  執行順序為:

  • setup_module()
  • setup_class(self)
  • setup_function()
  •  test_A
  • teardown_function()
  • setup_function()
  • test_B
  • teardown_function()
  • teardown_class(self)
  • teardown_module

二、重復執行

  • 挨個重復執行多次用例:pytest xxx.py -s --count=5
  • --repeat-scope可以設置參數(session , moduleclass或者function(默認值))pytest xxx.py -s --count=5 --repeat-scope=session
  • 單個用例標記:@pytest.mark.repeat(count)

三、跳過用例不執行

@pytest.mark.skip()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM