首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >python: pytest

python: pytest

作者头像
geovindu
发布2026-06-18 20:34:53
发布2026-06-18 20:34:53
1190
举报
代码语言:javascript
复制
# 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

代码语言:javascript
复制
# 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)
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-10-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档