pytest
命令會自動運行module
中的以test_
開頭或者_test
結尾的方法.
test.py
def fun(): # 會被測試命令忽略
assert 1 == 1
def test_fun(): # 測試命令會執行
assert 1 == 1 # 使用斷言
PS D:\code\test> pytest test.py
============================= test session starts =============================
platform win32 -- Python 3.6.5, pytest-3.5.1, py-1.5.3, pluggy-0.6.0
rootdir: D:\code\test, inifile:
plugins: remotedata-0.2.1, openfiles-0.3.0, doctestplus-0.1.3, arraydiff-0.2
collected 1 item
test.py . [100%]
========================== 1 passed in 0.06 seconds ===========================
參考:
https://learning-pytest.readthedocs.io/zh/latest/doc/intro/getting-started.html