官網介紹 全英警告!!!
https://docs.pytest.org/en/latest/getting-started.html#install-pytest
安裝pytest
pip3 install pytest
寫一個簡單的例子
# content of test_sample.py
def func(x):
return x + 1
def test_answer():
assert func(3) == 5
使用pytest.raises來測驗是否發生了意料之中的例外
# content of test_sysexit.py
import pytest
def f():
raise SystemExit(1)
def test_mytest():
with pytest.raises(SystemExit):
f()
Note:
使用 '-q' / '--quiet' 來使得輸出更加簡單
$ pytest -q test_sysexit.py . [100%] 1 passed in 0.12s
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/166774.html
標籤:Python
上一篇:FlaskWeb開發:基于Python的Web應用開發實戰
下一篇:爬蟲的基本概念
