運行指定的case
當我們寫了較多的cases時,如果每次都要全部運行一遍,無疑是很浪費時間的,通過指定case來運行就很方便了。
例子代碼:
test_aa.py
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_aa.py文件中的所有cases:
pytest test_aa.py
模式2:運行test_aa.py文件中的TestClassOne這個class下的兩個cases:
pytest test_aa.py::TestClassOne
模式3:運行test_aa.py文件中的TestClassTwo這個class下的test_one:
pytest test_aa.py::TestClassTwo::test_one
注意:定義class時,需要以T開頭,不然pytest是不會去運行該class的。