【pytest】失败用例,桌面截图

复制代码
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_makereport(item, call):
    # execute all other hooks to obtain the report object
    outcome = yield
    rep = outcome.get_result()  # rep可以拿到用例的执行结果详情

    if rep.when == "call" and rep.failed:
        im = ImageGrab.grab()

        # 使用 io.BytesIO 来捕获截图的二进制数据(PNG 格式)
        binary_image = io.BytesIO()
        im.save(binary_image, format='PNG')

        # 将字节流的位置重置到开头,以便我们可以读取数据
        binary_image.seek(0)

        # 现在 binary_image.read() 将返回截图的二进制数据(PNG 格式)
        png_binary_data = binary_image.read()
     allure.attach(png_binary_data, "异常截图", allure.attachment_type.PNG)
复制代码

 

posted on   张凌赫_帅  阅读(21)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示