[Pytest]運行指定的case


運行指定的case

  當我們寫了較多的cases時,如果每次都要全部運行一遍,無疑是很浪費時間的,通過指定case來運行就很方便了。

例子代碼:

class TestClassOne(object): def test_one(self): x = "this" assert 't'in x def test_two(self): x = "hello" assert hasattr(x, 'check') class TestClassTwo(object): def test_one(self): x = "iphone" assert 'p'in x def test_two(self): x = "apple" assert hasattr(x, 'check')

 

運行模式:

模式1:直接運行test_se.py文件中的所有cases:

pytest test_se.py

模式2:運行test_se.py文件中的TestClassOne這個class下的兩個cases:

pytest test_se.py::TestClassOne

模式3:運行test_se.py文件中的TestClassTwo這個class下的test_one:

pytest test_se.py::TestClassTwo::test_one


注意:定義class時,需要以T開頭,不然pytest是不會去運行該class的。



作者:呆呆冬
鏈接:https://www.jianshu.com/p/932a4d9f78f8
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。

 

參考文檔:

全功能Python測試框架:pytest


免責聲明!

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



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