python pytest

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章