• Django+Pytest搭建在线自动化测试平台实战1


    在这里插入图片描述
    在这里插入图片描述

    在这里插入图片描述
    在这里插入图片描述

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    1. 定义model(model驱动开发):model.py
    import pathlib
    from re import match
    
    from django.db import models
    
    # Create your models here.
    from django.utils import html
    
    
    class Task(models.Model):
        name = models.CharField("用例名称", max_length=20)
        print(name)
        case = models.FileField("用例文件", upload_to='tests/%Y_%m_%d_%H_%M_%S/')
        print(case)
        status = models.IntegerField(
            "测试状态", default=-1, choices=[
                (-1, '初始化'),
                (0, '马上执行'),
                (1, '正在执行测试用例'),
                (2, '正在生成测试报告'),
                (3, '执行完成')
            ]
        )
        run_datatime = models.DateTimeField("最近执行时间", null=True, blank=True)
    
        class Mate:  # 内部类:https://www.cnblogs.com/yum777/articles/8992640.html
            verbose_name_plural = verbose_name = '测试任务'
    
        def get_url(self, _type):
            """生成报告、或者测试日志的url"""
            print(_type)
            if self.case and self.status==3:
                case_path = pathlib.PurePosixPath(str(self.case))
                print(case_path)
                root_path = pathlib.PurePosixPath("/uploads")
    
                # python3.10 以后才能用 新特性 match-case,这里的环境是3.7;
                if _type=='report':
                    report_path = root_path / case_path.parent / "report/index.html"
                    print("report_path: {}".format(report_path))
                elif _type == '':
                    report_path = root_path / case_path.parent / "pytest.txt"
                    print("report_path: {}".format(report_path))
                elif _:
                    report_path = '_'
                    print("report_path: {}".format(report_path))
    
                return html.format_html(f" 点击查看")
    
            else:
                return "-"
    
    
    • 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

    cmd输入命令:python manage.py makemigrations (执行该命令才能让定义的model真正产生作用)
    在这里插入图片描述
    生成迁移脚本后需要输入:“python manage.py migrate” 命令来执行迁移脚本
    在这里插入图片描述
    2. 定义界面

    python manage.py createsuperuser
    
    • 1
    1. 执行数据库迁移
  • 相关阅读:
    【图像处理】浅谈直方图
    C#知识总结 基础篇(上)
    业务安全五重价值:防攻击、保稳定、助增收、促合规、提升满意度
    关于地图GIS的一次实践整理(下) Redis的GIS实践
    分类模型的Top 1和Top 5
    Python期末复习题:函数
    最后一块石头的重量 II
    python电子学会一级知识点总结
    web常见的漏洞的分类以及危害
    山东碱地3000亩水稻 国稻种芯·中国水稻节:德州大河粮仓
  • 原文地址:https://blog.csdn.net/luckyyuanyuan/article/details/126280186