Skip to content

Total time duration changed from seconds to minutes #607

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

Conversation

BleronHasani01
Copy link

No description provided.

@BeyondEvil
Copy link
Contributor

_ No description provided. _

Thank you for the PR.

But this has been redesigned in 4.0.0rc0.

Basically if it's milliseconds, it will show nnn ms and anything above 1 second will show hh:mm:ss.

Would love for you to try out 4.0.0rc0.

Thanks!

@BleronHasani01
Copy link
Author

Thank you for the comment @BeyondEvil

I installed this version pytest-html==4.0.0rc0 but the summary time is not showing in hh:mm:ss even that the total duration time is above 1 minute, the summary time is showing for example "10 tests ran in 288 seconds."

@BeyondEvil
Copy link
Contributor

BeyondEvil commented Mar 29, 2023 via email

@BleronHasani01
Copy link
Author

Thank you, please let me know when you do so.

@BeyondEvil
Copy link
Contributor

Took a look in the code, and I had updated it. But I set it to seconds:

const durationText = formattedAccTime.hasOwnProperty('ms') ? formattedAccTime.ms : formattedAccTime.seconds

I think the reasoning was to not break legacy/backwards-compat.

Need a minute to think about if I should updated. Spontaneously I think it should reflect the duration column.

@BeyondEvil
Copy link
Contributor

Please try 4.0.0rc1

@BleronHasani01
Copy link
Author

@BeyondEvil thank you! This version works all fine with the time duration but it caused me another issue. The problem is with the method getattr(report, "extra", []) which I'm using to add extra infos in report. Any idea why is this caused?

@BeyondEvil
Copy link
Contributor

BeyondEvil commented Apr 4, 2023 via email

@BleronHasani01
Copy link
Author

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'

@BeyondEvil
Copy link
Contributor

That is really weird. Why is pytest_html None? 🤔

Could you perhaps create a minimal conftest.py and test file so that I can reproduce it? Extra points if it's a repository I can just clone and run.

@BleronHasani01
Copy link
Author

@BeyondEvil I created a demo project you can clone and run it.
https://github.com/BleronHasani01/Prototype-.git

@BeyondEvil
Copy link
Contributor

Thank you for that!

The issue should however be reproducible with just a simple test and a few lines of conftest.py (if it’s a bug with the plugin).

Regardless, I’ll poke around and see if I can find something.

@BeyondEvil
Copy link
Contributor

BeyondEvil commented Apr 5, 2023

Ok, couple of things:

  • Change pytest_html = item.config.pluginmanager.getplugin("html") to import pytest_html (or from pytest_html import extras)
  • Change extra = getattr(report, "extra", []) to extra = getattr(report, "extras", [])
  • Change report.extra = extra to report.extras = extra

I'm going to add a deprecation warning for report.extra and getattr(report, "extra", [])

Thank you! 👊

@BleronHasani01
Copy link
Author

@BeyondEvil I really appreciate this, thank you very much for the support.

@BeyondEvil
Copy link
Contributor

I'll close this as finished. Please feel free to reopen if something isn't working as expected. 🙏

@BeyondEvil BeyondEvil closed this Nov 4, 2023
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 this pull request may close these issues.

2 participants