一、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
,module
,class
或者function
(默認值))pytest xxx.py -s --count=5 --repeat-scope=session - 單個用例標記:@pytest.mark.repeat(count)
三、跳過用例不執行
@pytest.mark.skip()