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

相关推荐
花酒锄作田3 小时前
使用 pkgutil 实现动态插件系统
python
前端付豪6 小时前
LangChain链 写一篇完美推文?用SequencialChain链接不同的组件
人工智能·python·langchain
曲幽7 小时前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
老赵全栈实战7 小时前
Pydantic配置管理最佳实践(一)
python
阿尔的代码屋13 小时前
[大模型实战 07] 基于 LlamaIndex ReAct 框架手搓全自动博客监控 Agent
人工智能·python
AI探索者1 天前
LangGraph StateGraph 实战:状态机聊天机器人构建指南
python
AI探索者1 天前
LangGraph 入门:构建带记忆功能的天气查询 Agent
python
FishCoderh1 天前
Python自动化办公实战:批量重命名文件,告别手动操作
python
躺平大鹅1 天前
Python函数入门详解(定义+调用+参数)
python
曲幽1 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama