
# 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)