allure.attach.file失败,错误为AttachmentType类型的对象不可JSON序列化

2024-06-16 08:26:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把截图附在诱惑报告上。但是,它会保持错误:

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 python 3.8 pytest 6.2.2 诱惑试验2.8.36 pywinauto 0.6.8


Tags: ofimportreporttrueobjectpytestistype