cmd命令运行exe程序 参数_httprunner学习15运行用例命令行参数详解

前言

HttpRunner 在命令行中启动测试时,通过指定参数,可实现丰富的测试特性控制。

命令行参数CLI

使用 -h 查看相关命令行参数

hrun -h

参数名称参数值参数说明
-h, —help不带参数查看帮助信息
-V, —version不带参数查看版本号
—no-html-report不带参数不生成测试报告
—html-report-nameHTML_REPORT_NAM重命名html报告名称
—html-report-templateHTML_REPORT_TEMPLATE自定义html报告模板,参数带上html模板的信息路径
—log-levelLOG_LEVEL日志等级,如:debug
—log-fileLOG_FILE指定日志文本保存路径
—dot-env-pathDOT_ENV_PATH指定环境变量.env的详细路径
—failfast不带参数运到失败后停止测试
—startprojectSTARTPROJECT指定项目的根目录
—validate[VALIDATE [VALIDATE …]]校验json格式
—prettify[PRETTIFY [PRETTIFY …]]各式化json文件

—no-html-report

不生成html报告,使用—no-html-report

hrun test_demo.yml —no-html-report

这样运行的时候,就不会生成html报告

D:\soft\untitled>hrun test_demo.yml --no-html-report
test_demo case1
INFO GET http://127.0.0.1:8000/api/test/demo
INFO status_code: 200, response_time(ms): 4.96 ms, response_length: 255 bytes
INFO start to extract from response object.
INFO start to validate.
.

----------------------------------------------------------------------
Ran 1 test in 0.014s

OK

—html-report-name

—html-report-name 用于指定测试报告的名称

hrun test_demo.yml —html-report-name yoyo

这样运行之后,会再当前的report目录下,生成一个yoyo的文件夹

fcee76c2ae7720906461731232e1a3fd.png

—html-report-template

自定义测试报告模板,后面参数是模板报告的绝对路径

hrun test_demo.yml —html-report-template /path/templates/extent_report_template.html

如果指定报告名称的话,需要修改源码,详情参考httprunner学习10-测试报告ExtentReport

—log-level

打印日志等级,使用—log-level参数,日志有五个等级:debug < info < warn < error < critical

各等级的含义:

  • debug: 级别最低,用户开发过程中的调试

  • info:

    打印程序运行是的正常的信息,用于替代print输出

  • warn: 打印警告信息,不影响程序的运行

  • error: 程序运行出错,可以修复,常用在except异常捕获之后

  • critical: 非常严重,无法修复,程序继续运行的话后果非常严重

设置了日志等级后,调用比等级低的日志记录函数则不会输出。

httprunner默认使用info等级,不带 --log-level info 参数结果也是一样的

hrun test_demo.yml —log-level info

设置debug等级,打印最详细的内容

hrun test_demo.yml —log-level debug

另外三个等级warn/error/critical,只有有警告或者报错时候,才有日志输出,所以用的很少

D:\soft\untitled>hrun test_demo.yml --log-level warn
test_demo case1
.

----------------------------------------------------------------------
Ran 1 test in 0.006s

OK

D:\soft\untitled>hrun test_demo.yml --log-level error
test_demo case1
.

----------------------------------------------------------------------
Ran 1 test in 0.006s

OK

D:\soft\untitled>hrun test_demo.yml --log-level critical
test_demo case1
.

----------------------------------------------------------------------
Ran 1 test in 0.007s

OK

—log-file

—log-file 参数保存日志文件到指定的目录,保存日志文件到yoyo.txt

hrun test_demo.yml —log-file yoyo.txt

在当前运行的目录,会生成一个yoyo.txt文件

2019-09-28 22:43:11,492 - INFO - [32mGET http://127.0.0.1:8000/api/test/demo
2019-09-28 22:43:11,498 - INFO - [32mstatus_code: 200, response_time(ms): 6.0 ms, response_length: 255 bytes
2019-09-28 22:43:11,498 - INFO - [32mstart to extract from response object.
2019-09-28 22:43:11,498 - INFO - [32mstart to validate.
2019-09-28 22:43:11,503 - INFO - [32mStart to render Html report ...
2019-09-28 22:43:11,578 - INFO - [32mGenerated Html report: D:\soft\untitled\reports\1569681791.html

由于日志的输出有加颜色,所以保存的时候会有一些乱码,我稍微改了下httprunner/logger.py文件的日志内容,但还是有一点乱码

def setup_logger(log_level, log_file=None):
"""setup root logger with ColoredFormatter."""
level = getattr(logging, log_level.upper(), None)
if not level:
color_print("Invalid log level: %s" % log_level, "RED")
sys.exit(1)

# hide traceback when log level is INFO/WARNING/ERROR/CRITICAL
if level >= logging.INFO:
sys.tracebacklimit = 0
formatter = ColoredFormatter(
u"%(log_color)s%(bg_white)s%(levelname)-8s%(reset)s %(message)s",
datefmt=None,
reset=True,
log_colors=log_colors_config
)
if log_file:
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') # 加了这句
handler = logging.FileHandler(log_file, encoding='utf-8')
else:
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logging.root.addHandler(handler)
logging.root.setLevel(level)

其它

—dot-env-path 用于指定.env文件的目录

hrun test_demo.yml —dot-env-path d:\path\to.env

—failfast 遇到失败停止测试

hrun test_demo.yml —failfast

—validate 校验json格式,格式正确返回OK,若 JSON 文件格式存在异常,则打印详细的报错信息,精确到错误在文件中出现的行和列。

hrun —validate test_login2.json

—prettify 用于格式化json文件内容

hrun —prettify test_login2.json

D:\soft\untitled>hrun --validate test_login2.json
Start to validate JSON file: test_login2.json
OK

D:\soft\untitled>hrun --prettify test_login2.json
Start to prettify JSON file: test_login2.json
success: test_login2.pretty.json

2019第一期《python测试开发》课程,10月13号开学!

本期上课时间:10月13号-12月8号,每周六、周日晚上20:30-22:30

联系QQ:283340479

2019第一期《python测试开发》课程,10月13号开学

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
pytest命令行运行参数有很多,以下是一些常用的参数: -s:输出调试信息,包括print打印的信息。 -v:显示更详细的信息。 -n=num:启用多线程或分布式运行测试用例。需要安装 pytest-xdist 插件模块。 -k=value:用例的nodeid包含value值则用例被执行。 -m=标签名:执行被 @pytest.mark.标签名 标记的用例。 -x:只要有一个用例执行失败就停止当前线程的测试执行。 –maxfail=num:与-x功能一样,只是用例失败次数可自定义。 –reruns=num:失败用例重跑num次。需要安装 pytest-rerunfailures 插件模块。段的相关参数,可以改变pytest默认的测试用例规则。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Pytest用例运行方式以及参数](https://blog.csdn.net/m0_65185904/article/details/127569021)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [pytest常用执行参数详解](https://blog.csdn.net/FloraCHY/article/details/131823450)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值