pytest-html icon indicating copy to clipboard operation
pytest-html copied to clipboard

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

Open qupfer opened this issue 5 years ago • 0 comments
trafficstars

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

qupfer avatar Nov 04 '20 09:11 qupfer