Skip to content

report "extra" attribute not working in 4.0.0 #624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BeyondEvil opened this issue Apr 5, 2023 · 0 comments · Fixed by #626
Closed

report "extra" attribute not working in 4.0.0 #624

BeyondEvil opened this issue Apr 5, 2023 · 0 comments · Fixed by #626

Comments

@BeyondEvil
Copy link
Contributor

          Hi @BeyondEvil this is the method that I'm using to create report, as you can see there is extra = getattr(report, "extra", []) that I'm using to add extra infos in report like url, screenshoots etc. The issue that is returned you can find under the second line:

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
pytest_html = item.config.pluginmanager.getplugin("html")
outcome = yield
report = outcome.get_result()
setattr(report, "duration_formatter", "%H:%M:%S.%f")
extra = getattr(report, "extra", [])
test_fn = item.obj
docstring = getattr(test_fn, 'doc')
if docstring:
report.nodeid = docstring
if report.when == "call":
# report.nodeid = item.name
extra.append(pytest_html.extras.url(TestData.BASE_URL))
xfail = hasattr(report, "wasxfail")
if (report.skipped and xfail) or (report.failed and not xfail):
# Get the directory where the Report is saved
try:
reports_directory = os.path.dirname(item.config.option.htmlpath)
except TypeError:
if "tests" in os.path.abspath(os.curdir):
os.chdir("..")
reports_directory = os.path.abspath(os.curdir) + "/reports"
# Set the name of the screenshot [failed_test_name] + [current_date] + [type of image]
scr_file_name =
os.environ.get('PYTEST_CURRENT_TEST').replace('(call)', '').split(':')[-1].split('__')[0]
+ datetime.now().strftime("%d-%m-%Y-%H-%M") + ".png"
# Set the directory where the screenshot should be saved
destination_file = os.path.join(reports_directory, scr_file_name)
# Take the actual screenshot
driver.save_screenshot(destination_file)
if scr_file_name:
html = '

<img src="%s" alt="screenshot" style="width:300px;height=200px"'
'onclick="window.open(this.src)" align="right"/>
' % scr_file_name
extra.append(pytest_html.extras.html(html))
report.extra = extra


INTERNALERROR> extra.append(pytest_html.extras.url(TestData.BASE_URL))
INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'extras'

Originally posted by @BleronHasani01 in #607 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant