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

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