pytest-dev / pytest-dev/pytest-html

image is not displaying on the report page

Open
#265 19 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug next-gen
Dominant language
Python
Stars
779
Forks
260
PR merge metrics
No merged PRs in 30d

Description

image
The image link shown on the page is relative to localhost, which shows 404
http://localhost:63342/screenshots/my_screenshot.png

To Reproduce
keep a png file named my_screenshot.png in the root of project
contents of conftest.py


import os

@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
    outcome = yield
    report = outcome.get_result()
    pytest_html = item.config.pluginmanager.getplugin('html')
    extra = getattr(report, 'extra', [])

    main_script_dir = os.path.dirname(__file__)
    rel_path = "screenshots/my_screenshot.png" #hardcoded image file temporarily #TODO to get from driver
    image = pytest_html.extras.image(os.path.join(main_script_dir, rel_path))
    extra.append(image)
    report.extra = extra

Run with
pytest --html=report.html
Also have tried with --self-contained-html

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

Start with the conftest.py reproduction and run pytest --html=report.html with and without --self-contained-html. Trace how pytest_html.extras.image handles screenshots/my_screenshot.png and how the report renders the resulting URL. Done means the PNG displays on the report page instead of resolving to the broken localhost path.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, python
Domain
testing-qa, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.