前提:需要安装pytest和pytest-html(生成html测试报告)
pip install pytest 和 pip install pytest-html
命名规则
Pytest单元测试中的类名和方法名必须是以test开头,执行中只能找到test开头的类和方法,比unittest更加严谨
Pytest生成自带的html测试报告
需要下载pytest-html模块(python自带的生成测试报告模块
pip install pytest-html
运行指定模块指定类指定用例,冒号分割,并生成测试报告
import pytest
class TestClass(object):
def setup(self):
print("我是setup")
@pytest.mark.skip()
def test01(self):
#断言判断测试用例
assert 2 == 2
print("我是test01")
def test02(self):
print("我是test02")
assert 2 == 3
def teardown(self):
print("我是teardown")
#--html=./report.html 生成的测试报告 第二个是模块的名字
if __name__ == '__main__':
# pytest.main(["--ht