Skip to content

Instantly share code, notes, and snippets.

@maropu
Forked from harupy/show_elapsed_time.py
Created January 26, 2021 23:43
Show Gist options
  • Save maropu/16d415a1b9aa05b4d2f9b731a6435103 to your computer and use it in GitHub Desktop.
Save maropu/16d415a1b9aa05b4d2f9b731a6435103 to your computer and use it in GitHub Desktop.
@pytest.hookimpl(hookwrapper=True)
def pytest_report_teststatus(report, config):
outcome = yield
res = outcome.get_result()
attr_name = "___TIME___"
if report.when == "setup":
# HACK: store the start time in `config`
setattr(config, attr_name, time.time())
elif report.when == "call":
start = getattr(config, attr_name)
new_res = res[:2] + (res[2] + " ({:.3f} s)".format(time.time() - start),)
outcome.force_result(new_res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment