python: pytest in thonny IDE

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 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 @   ®Geovin Du Dream Park™  阅读(16)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2023-10-16 c: string
2022-10-16 Java: null object Pattern
2022-10-16 javascript: Webcam
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示