【问题标题】:allure.attach.file fails with error Object of type AttachmentType is not JSON serializableallure.attach.file 失败并出现错误 AttachmentType 类型的对象不是 JSON 可序列化的
【发布时间】:2021-04-03 13:34:45
【问题描述】:

我正在尝试将屏幕截图附加到 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)

环境: 视窗 10 蟒蛇3.8 pytest 6.2.2 诱惑-pytest 2.8.36 pywinauto 0.6.8

【问题讨论】:

    标签: python pytest allure


    【解决方案1】:

    位置参数形式导致错误。 代码应该是:

    allure.attach.file(r'D:\image_01.png', attachment_type=allure.attachment_type.PNG)
    

    【讨论】:

      猜你喜欢
      • 2018-10-10
      • 1970-01-01
      • 2022-12-21
      • 2021-01-19
      • 2019-04-29
      • 1970-01-01
      • 2021-12-24
      • 2021-06-07
      • 2020-04-13
      相关资源
      最近更新 更多