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