pytest-dev / pytest-dev/pytest-html
binascii.Error if media file not present
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 779
- Forks
- 260
- PR merge metrics
- No merged PRs in 30d
Description
Using pytest-html 3.1.1 and xdist 2.5.0
When passing a non existing file as media, pytest-html will raise an error during report generation.
To reproduce: Add extra.append(extras.image("doesnotexist")) in a report.
Actually I am looking for two things here
- binascii.Error should not happen. What encoding should the passed 'content' string have?
- How to reference local media, which does not yet exist as a file?
More details:
We are using 'extra.addImage()' in combination with pytest xdist.
When generating the html report, the media files from the different testing engines are not yet rsynced, so pytest-html will not see most of the files during report generation.
Because of this, the check (plugin.py 406ff, version 3.1.1)
is_uri_or_path = content.startswith(("file", "http")) or isfile(content)
is False.
Subsequently, the 'content' is treated as an external link, and decoded with this:
content = b64decode(content.encode("utf-8"))
This causes an binascii.Error, and no html report is generated.
The error can be triggered easily by adding an invalid media,like
extra.append(extras.image("doesnotexist"))
to a report.
The quickfix for us was to always set is_uri_or_path True.
Media files are referenced locally, so prefixing the uri with "http" or "file" is a bit difficult.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with extra.append(extras.image("doesnotexist")) and inspect the media handling around plugin.py 406ff. Trace the is_uri_or_path check and subsequent base64 decoding, then review the report-generation path used with pytest-xdist. Done means a missing local media reference no longer prevents HTML report generation and its handling is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100