python: pytest in thonny IDE
# encoding: utf-8 # 版权所有 2024 ©涂聚文有限公司 # 许可信息查看: # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 3.11 # OS : windows 10 # Datetime : 2024/10/17 8:22 # User : geovindu # Product : PyCharm # Project : IctGame # File : studnet.py # explain : 学习 class StudentData: """ """ def __init__(self): """ """ self.__data = None def connect(self, datafile:str): """ :param datafile: :return: """ with open(datafile) as jsonfile: self.__data = json.load(jsonfile) def getdata(self, name:str): """ :param name: :return: """ for stu in self.__data['students']: if stu['name'] == name: return stu def close(self): """ :return: """ pass
# encoding: utf-8 # 版权所有 2024 ©涂聚文有限公司 # 许可信息查看: # 描述: # Author : geovindu,Geovin Du 涂聚文. # IDE : PyCharm 2023.1 python 3.11 # OS : windows 10 # Datetime : 2024/10/17 8:22 # User : geovindu # Product : PyCharm # Project : IctGame # File : teststudnet.py # explain : 学习 from student import StudentData import pytest #需要安裝 在開始CMD 運行 pip install pytest pip install pytest-html import pytest_html import webbrowser @pytest.fixture(scope='module') def db(): """ :return: """ print('*****SETUP*****') db = StudentData() db.connect('data.json') yield db print('******TEARDOWN******') db.close() def testScottData(db): """ :param db: :return: """ scottdata = db.getdata('Jason') assert scottdata['id'] == 1 assert scottdata['name'] == 'geovindu' assert scottdata['result'] == 'pass' def testMarkData(db): """ :param db: :return: """ markdata = db.getdata('Dau') assert markdata['id'] == 2 assert markdata['name'] == 'sibodu' assert markdata['result'] == 'fail' if __name__ == '__main__': """ """ # #pytest.main() pytest.main(['-v','geovindu.py','--html=geovindu.html']) #生成测试报告 ::bll webbrowser.open('geovindu.html',new=0,autoraise=True)
生成测试报告
https://www.lambdatest.com/blog/generating-xml-and-html-report-in-pyunit-for-test-automation/ unittest
https://codedec.com/tutorials/how-to-generate-html-report-for-pytest-execution/
https://docs.pytest.org/en/7.1.x/_modules/_pytest/reports.html
哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)生存.---Geovin Du(涂聚文)