代碼示例:
import pytest
@pytest.fixture(autouse=True,scope='session') #autouse=True,scope='session'
def session_scope():
print("#######################0")
yield
print("~~~~~~~~~~~~~~~~~~~~~~~1")
@pytest.mark.add
#@pytest.mark.usefixtures("session_scope")
class Test_case():
def test_one(self):
print("測試用例")
if __name__ == '__main__':
pytest.main(["-m","add"])
設置:
第一種方法:
1.打開pycharm右上角Edit Config....
2.選擇python tests-----py.test
3.設置代碼路徑,名稱隨意,python版本隨意,然后點擊保存
4.驗證成功
第二種方法:
在運行時候加個-s就行了,例如 pytest.main(["-m","add",“-s”])