httprunner3 log放到allure中显示

httprunner3的log本身是不能在allure上展示的

可以通过改写\Lib\site-packages\httprunner\runner.py文件中的test_start方法实现报告存放allure中展示

添加一行

allure.attach.file(self.__log_path, name='log', attachment_type=allure.attachment_type.TEXT)

改写代码如下:登录后复制

def test_start(self, param: Dict = None) -> "HttpRunner":
        """main entrance, discovered by pytest"""
        self.__init_tests__()
        self.__project_meta = self.__project_meta or load_project_meta(
            self.__config.path
        )
        self.__case_id = self.__case_id or str(uuid.uuid4())
        # self.__log_path = self.__log_path or os.path.join(
        #     self.__project_meta.RootDir, "logs", f"{self.__case_id}.run.log"
        # )
        self.__log_path = os.path.join(self.__project_meta.RootDir, "logs", "{}.txt".format(time.time()))
        log_handler = logger.add(self.__log_path, level="DEBUG")

        # parse config name
        config_variables = self.__config.variables
        if param:
            config_variables.update(param)
        config_variables.update(self.__session_variables)
        self.__config.name = parse_data(
            self.__config.name, config_variables, self.__project_meta.functions
        )

        if USE_ALLURE:
            # update allure report meta
            allure.dynamic.title(self.__config.name)
            allure.dynamic.description(f"TestCase ID: {self.__case_id}")

        logger.info(
            f"Start to run testcase: {self.__config.name}, TestCase ID: {self.__case_id}"
        )

        try:
            return self.run_testcase(
                TestCase(config=self.__config, teststeps=self.__teststeps)
            )
        finally:
            allure.attach.file(self.__log_path, name='log', attachment_type=allure.attachment_type.TEXT)
            logger.remove(log_handler)
            logger.info(f"generate testcase log: {self.__log_path}")

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值