pytest-dev / pytest-dev/pytest-html

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

Open
#363 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
Python
Stars
779
Forks
260
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The report uses pytest_html.extras.image and report.extra; start by comparing the documented image API with the base64 input shown in the issue. Done means the generated self-contained HTML report displays the embedded image.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, python
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.