postman脚本生成可执行文件(6)

一.通过Python脚本(executescript.py)执行newman指令

javascript 复制代码
#!usr/bin/python
import subprocess
from datetime import datetime

class Newman_automate():
    '''
    Newman_automate():该类主要是定义postman脚本执行
    __path:cmd命令行中执行newnan脚本指令(1.不包括测试报告文件名;2.文件路径要专义)
    '''
    __path='newman run C:\\Users\\ZhuQing\\OneDrive\\桌面\\postman\\JSONcrip -r html --reporter-html-export  C:\\Users\\ZhuQing\\OneDrive\\桌面\\postman\\'
    def file_name(self):
        '''
        :file_name()函数定义测试报告文件名(文件名以日期命名)
        :return:文件名
        '''
        try:
            now_date=datetime.now().strftime("%Y-%m-%d_%H%M%S")+'.html'
            return now_date
        except Exception as ex:
            print(ex)
    def newman_order(self):
        '''
        ;newman_order()该函数定义通过cmd命令行执行的newman完整指令
        :return: 返回newman完整指令
        '''
        try:
            filename =self.__path+Newman_automate.file_name(self)
            # print(filename)
            return filename
        except Exception as ex:
            print(ex )
    def open_cmd(self):
        '''
        :open_cmd():该函数主要是打开cmd窗口并执行指令
        :param newman:指令
        :return:
        '''
        try:
            filename =Newman_automate.newman_order(self)
            # print('文件路径;',filename)
            subprocess.call(filename,shell=True)
        except Exception as ex:
            print(ex)

if __name__=="__main__":
    c=Newman_automate()
    c.open_cmd()

二.打包executescript.py文件(即生成可执行文件)

1.在executescript.py文件夹内执行打包指令:pyinstaller -F executescript.py

javascript 复制代码
D:\Python_stady>pyinstaller -F executescript.py


补充:

1...pyinstaller打包安装

2.定时执行postman脚本

3.测试报告内容如下:

相关推荐
__lost9 分钟前
Python图像变清晰与锐化,调整对比度,高斯滤波除躁,卷积锐化,中值滤波钝化,神经网络变清晰
python·opencv·计算机视觉
海绵波波10714 分钟前
玉米产量遥感估产系统的开发实践(持续迭代与更新)
python·flask
逢生博客1 小时前
使用 Python 项目管理工具 uv 快速创建 MCP 服务(Cherry Studio、Trae 添加 MCP 服务)
python·sqlite·uv·deepseek·trae·cherry studio·mcp服务
堕落似梦1 小时前
Pydantic增强SQLALchemy序列化(FastAPI直接输出SQLALchemy查询集)
python
坐吃山猪2 小时前
Python-Agent调用多个Server-FastAPI版本
开发语言·python·fastapi
Bruce-li__2 小时前
使用Django REST Framework快速开发API接口
python·django·sqlite
小兜全糖(xdqt)2 小时前
python 脚本引用django中的数据库model
python·django
Arenaschi3 小时前
SQLite 是什么?
开发语言·网络·python·网络协议·tcp/ip
纪元A梦3 小时前
华为OD机试真题——推荐多样性(2025A卷:200分)Java/python/JavaScript/C++/C语言/GO六种最佳实现
java·javascript·c++·python·华为od·go·华为od机试题
仙人掌_lz3 小时前
人工智能与机器学习:Python从零实现性回归模型
人工智能·python·机器学习·线性回归