運行指定的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
來源:簡書
著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。
參考文檔: