python - allure.attach.file 失败并出现错误 AttachmentType 类型的对象不是 JSON 可序列化的
问题描述
我正在尝试将屏幕截图附加到 Allure 报告。但是它一直失败并出现错误:
TyperError: Object of type AttachmentType is not JSON serializable
这是我的 conftest.py 中的代码:
import pytest
import allure
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
outcome = yield
report = outcome.get_result()
if report.whem == "call" and report.failed:
with allure.step("Failure screenshot"):
allure.attach.file(r'D:\image_01.png', allure.attachment_type.PNG)
环境:Windows 10 python 3.8 pytest 6.2.2 allure-pytest 2.8.36 pywinauto 0.6.8
解决方案
位置参数形式导致错误。代码应该是:
allure.attach.file(r'D:\image_01.png', attachment_type=allure.attachment_type.PNG)
推荐阅读
- c# - “无限”异步并行 foreach 循环
- javascript - 带有 setInterval 的 datatable.ajax.reload() 会导致页面崩溃,如何避免内存泄漏?
- oracle - 无法在 clob 数据类型列中插入 base64 字符串
- windows-10 - 将区分大小写的文件复制/同步到 Windows 10 上的文件夹中
- django - 如何在 Django Summernote 中显示编程片段的代码块?
- sql - 优化两个日期之间的工作日统计查询
- ejabberd - 如何使用 smack 库从客户端搜索 ejabberd 服务器上的注册用户?
- javascript - 查询选择器javascript未在python selenium中执行
- tensorflow - TypeError:('关键字参数不理解:','组')
- vue.js - vue.js 动态导入和加载组件