pytest-dev / pytest-dev/pytest-html

Unable to fetch the path for theHTML report using the item.config.option.html in pytest-html

Open
#492 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hey, Just try to build a new Html report for the test cases & attach a screenshot for the Failed test to My Html Report.
Got this piece of Code but was unable to get the HTML path for the report which is being created.
Is there a better to get the path without Hard Coding it, Please share?

OS : Windows 64
pytest==6.2.5
pytest-html==3.1.1

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
pytest_html = item.config.pluginmanager.getplugin("html")
outcome = yield
report = outcome.get_result()
extra = getattr(report, "extra", [])
if report.when == "call":
extra.append(pytest_html.extras.url("https://www.saucedemo.com/"))
xfail = hasattr(report, "wasxfail")
if (report.skipped and xfail) or (report.failed and not xfail):
report_dir = os.path.dirname(item.config.option.html)
file = report.nodeid.replace("::","_") + ".png"
dest = os.path.join(report_dir,file)
driver.save_screenshot(dest)
extra.append(pytest_html.extras.html("

Additional HTML"))
report.extra = extra

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 by tracing the pytest_runtest_makereport hook and the item.config.option.html value used in the report-path calculation. No project file or test is named in the issue, so identify the relevant plugin entry point and existing tests first; done should be a supported, non-hard-coded way to locate the generated report path.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.