前提:需要安装
pytest
和
pytest-html(
生成
html
测试报告)
pip install pytest 和 pip install pytest-html
1:命名规则
Pytest
单元测试中的类名和方法名必须是以
test
开头
,
执行中只能找到
test
开头的类和方法,比unittest 更加严谨
unittest : Setup>> setupclass , teardown >> teardownclassPytest: setup, setup_class 和 teardown, teardown_class 函数 ( 和 unittest 执行效果一样 )运行于测试方法的始末,即 : 运行一次测试函数会运行一次 setup 和 teardown运行于测试方法的始末 , 但是不管有多少测试函数都只执行一次 setup_class 和 teardown_class
2:Pytest生成自带的html测试报告
前提条件:需要下载pytest-html模块(python自带的生成测试报告模块)
pip install pytest-html
案例一
pytest.main("
模块
.py")
【运行指定模块下,运行所有
test
开头的类和测试用例】
pytest . main ([ "--html=./report.html" , " 模块 .py" ])