文档:https://docs.pytest.org/en/latest/contents.html#toc
PS:前提:本地已配置完成Python环境
第一种方式:在命令行输入
pip install pytest
第二种方式 :PyCharm直接安装
Pytest第三方库学习文档::https://pypi.org/search/?q=pytest
# pytest安装与依赖
pip install pytest
#升级Pytest
pip install -U pytest
#界面美化
pip install pytest-sugar
# 重新运行出错的测试用例
pip install pytest-rerunfailures
#进行多任务、同时并发执行测试用例
pip install pytest-xdist
# 对测试用例进行断言
pip install pytest-assume
# 会生成html测试报告
pip install pytest-html
# 控制用例执行顺序
pip install pytest-ordering
# 用例随机执行
pip install pytest-random-order
# 查看所有第三方库
pip list
#查看Pytest帮助文档
pytest -h
Pytest运行规则,对文件名、类名、函数名命名有一定的规范
#test_sample.py
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5
执行结果如下:
$ pytest
============================= test session starts =============================
collected 1 items
test_sample.py F
================================== FAILURES ===================================
_________________________________ test_answer _________________________________
def test_answer():
> assert inc(3) == 5
E assert 4 == 5
E + where 4 = inc(3)
test_sample.py:5: AssertionError
========================== 1 failed in 0.04 seconds ===========================
以上是我学习的笔记,简单分享一下,希望对大家有帮助~~~