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.测试报告内容如下:

相关推荐
程序员佳佳1 小时前
2025年大模型终极横评:GPT-5.2、Banana Pro与DeepSeek V3.2实战硬核比拼(附统一接入方案)
服务器·数据库·人工智能·python·gpt·api
刘某的Cloud2 小时前
列表、元组、字典、集合-组合数据类型
linux·开发语言·python
ys~~2 小时前
git学习
git·vscode·python·深度学习·学习·nlp·github
Mqh1807622 小时前
day46 Grad-CAM
python
郝学胜-神的一滴2 小时前
Python魔法函数一览:解锁面向对象编程的奥秘
开发语言·python·程序人生
白露与泡影3 小时前
使用systemd,把服务装进 Linux 心脏里~
linux·运维·python
yaoh.wang3 小时前
力扣(LeetCode) 100: 相同的树 - 解法思路
python·程序人生·算法·leetcode·面试·职场和发展·跳槽
Lilixxs3 小时前
wireshark LLDP 协议抓包获取 M580 PLC 网口地址
网络·测试工具·wireshark·plc·施耐德·lldp·m580
Sunsets_Red3 小时前
2025 FZYZ夏令营游记
java·c语言·c++·python·算法·c#
guslegend3 小时前
第2章:LangChain大模型工具开发(Agent工具能力)
python