Skip to content

[Question] How add an image (from disk) to self-contained-html #363

Open
@qupfer

Description

@qupfer

Edit: got ist, need to convert the base64 bin file to string
Edit2: seem not to be enough :-)
Hi,

I'm relativ new to python/pytest.

I want to add some images to the html report directly. As the documentation says, its not (always) possible as path, so I want to add it directly.

I tried something like this, but it doesn't work :-)

# [...]
picpath="/path/to/my/pic"
            # add image as b64 to embed it in the html file
            with open(picpath, mode="rb") as pic:
                b64pic = base64.b64encode(pic.read())
            extra.append(pytest_html.extras.image(b64pic, mime_type='image/png', extension='png'))
            report.extra = extra

The report is created and the image is in the html file, but not shown. So I think, there is still an issue with the "b64pic" part.

Can somebody give me a hint?

Thanks a lot

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionThis PR is asking whether it is possible to achieve a certain outcome

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions