Pytest+Yaml+Request+Allure+PyMsql+Jenkins+GitLab框架源代码之(四)运行主程序

  • all.py:主运行程序
    在这里插入图片描述
import os
import time
import pytest

if __name__ == '__main__':
    pytest.main()

    time.sleep(1)
    # os.system("allure generate ./reports/temp -o ./reports/allure --clean")
    # copy environment.properties  .\\reports\\temp 设置allure报告环境变量
    os.system("copy environment.properties  .\\reports\\temp")
    os.system("allure generate ./reports/temp -o ./reports/allure --clean")


import json


# 修改allure报告的报告标题
#  测试

def set_report_title(json_file_path, key, new_value):
    # 读取JSON文件
    with open(json_file_path, 'r', encoding='utf-8') as file:
        data = json.load(file)

    # 修改特定内容
    data['reportName'] = new_value

    # 将修改后的内容写回到文件
    with open(json_file_path, 'w', encoding='utf-8') as file:
        json.dump(data, file, ensure_ascii=False, indent=4)


# 调用set_report_title方法,设置测试报告报告title

json_file_path = r'./reports/allure/widgets/summary.json'
set_report_title(json_file_path, 'reportName', 'XX互联财务接口自动化测试报告')
  • conftest.py:清除旧数据
import pytest
from common.yaml_util import clean_file

@pytest.fixture(scope='session',autouse=True)
def clean_extract():
    clean_file('/config/extract.yml')


  • debugtalk.py:热加载文件,用于封装常用函数
# -*- coding: UTF-8 -*-
import random
from common.yaml_util import read_file


class DebugTalk:

    # 获取随机数
    def get_random_number(self,mix,max):
        return random.randint(int(mix),int(max))

    # 获取基础路径
    def get_base_url(self,one_node):
        return read_file('/config/config.yml','base',one_node)

  • environment.properties:生成Allure报告展示环境数据
Author=zhangweixu
ProjectName=FenMiApiFrame
BaseUrl=https://XXXX.com
GitLab=http://XXXX:8010/root/fenmi_api_frame
PythonVersion=3.7.0
PytestVersion=7.4.4
AllureVersion=2.18.1
  • pytest.ini :运行配置文件
[pytest]
; addopts = -vs --alluredir=reports/temp
addopts = -vs --alluredir=reports/temp --clean-alluredir
; addopts = -vs --html=reports/report.html
testpaths = testcases/fenmi testcases/hlj_sec
; testpaths = testcases/fenmi testcases/weixin testcases/Zgen testcases/hlj_sec
python_files = test_*.py
python_classes = Test*
python_functions = test_*

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CesareCheung

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值