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

posted @ 2024-10-16 18:12  ®Geovin Du Dream Park™  阅读(13)  评论(0编辑  收藏  举报