问答 httprunner3 中,py 脚本设置 CSV 参数化,大佬指点一二吗

2683tantan · April 16, 2021 · Last by 2683tantan replied at April 19, 2021 · 2389 hits

httprunner3 中,py 脚本设置 CSV 参数化,大佬指点一二吗

共收到 13 条回复 时间 点赞

也不知道你啥需求,建议补充下,然后 github 上有参数化的示例可以先看看
https://github.com/httprunner/httprunner/blob/master/examples/postman_echo/request_methods/request_with_parameters.yml

httprunner3 已经完美支持 pytest 了,pytest 支持 csv 参数化,可以去学习一下 pytest 的@pytest.mark.parametrize()



帮忙看下这个有什么问题吗?跟着教程写的,一直报错

from httprunner import Parameters


class TestCaseRequestWithParameters(HttpRunner):
    @user1ize(
        "param",
        Parameters(
            {
                "user_agent": ["iOS/10.1", "iOS/10.2"],
                "username-password": "${parameterize(request_methods/account.csv)}",
                "app_version": "${get_app_version()}",
            }
        ),
    )
    def test_start(self, param):
        super().test_start(param)

1.参数化写法不对;
2.需要通过 pytest 命令执行
示例链接:https://github.com/httprunner/httprunner/blob/master/examples/postman_echo/request_methods/request_with_parameters_test.py

2683tantan 回复


传错图了

2683tantan 回复

2683tantan 回复

你运行的时候不是用 pytest 吧?

幺叁叁 回复

只有命令才能运行成功吗

2683tantan 回复

用 pycharm 要设置用 pytest 运行

10Floor has deleted
2683tantan · #11 · April 17, 2021 Author
Author only
幺叁叁 回复

方法可行👍
还有一个新的问题:生成报告的命令只能在 cmd 窗口和 terminal 中运行成功,os.system()调用就不行

2683tantan 回复

不知道你os.system()是放在哪执行的,可以单独创建个 py 文件来执行测试,在用例跑完之后再通过os.system()来生成报告, 示例
run.py

import pytest
import os

if __name__ == '__main__':
    pytest.main(['request_with_parameters_test.py', '-s', '-vvv', '--alluredir', 'reports/xml'])
    os.system('allure generate -c -o reports/html')

幺叁叁 回复

我用的 hrun 命令,也可以了,感谢大佬

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up