mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 00:04:42 +04:00
Merge pull request #3029 from adamchainz/improve_duration_timing
Improve hook duration timing
This commit is contained in:
commit
c9945b9aa3
3 changed files with 4 additions and 4 deletions
|
|
@ -187,7 +187,7 @@ def _run_single_hook(
|
||||||
|
|
||||||
if not hook.pass_filenames:
|
if not hook.pass_filenames:
|
||||||
filenames = ()
|
filenames = ()
|
||||||
time_before = time.time()
|
time_before = time.monotonic()
|
||||||
language = languages[hook.language]
|
language = languages[hook.language]
|
||||||
with language.in_env(hook.prefix, hook.language_version):
|
with language.in_env(hook.prefix, hook.language_version):
|
||||||
retcode, out = language.run_hook(
|
retcode, out = language.run_hook(
|
||||||
|
|
@ -199,7 +199,7 @@ def _run_single_hook(
|
||||||
require_serial=hook.require_serial,
|
require_serial=hook.require_serial,
|
||||||
color=use_color,
|
color=use_color,
|
||||||
)
|
)
|
||||||
duration = round(time.time() - time_before, 2) or 0
|
duration = round(time.monotonic() - time_before, 2) or 0
|
||||||
diff_after = _get_diff()
|
diff_after = _get_diff()
|
||||||
|
|
||||||
# if the hook makes changes, fail the commit
|
# if the hook makes changes, fail the commit
|
||||||
|
|
|
||||||
|
|
@ -293,7 +293,7 @@ def test_verbose_duration(cap_out, store, in_git_dir, t1, t2, expected):
|
||||||
write_config('.', {'repo': 'meta', 'hooks': [{'id': 'identity'}]})
|
write_config('.', {'repo': 'meta', 'hooks': [{'id': 'identity'}]})
|
||||||
cmd_output('git', 'add', '.')
|
cmd_output('git', 'add', '.')
|
||||||
opts = run_opts(verbose=True)
|
opts = run_opts(verbose=True)
|
||||||
with mock.patch.object(time, 'time', side_effect=(t1, t2)):
|
with mock.patch.object(time, 'monotonic', side_effect=(t1, t2)):
|
||||||
ret, printed = _do_run(cap_out, store, str(in_git_dir), opts)
|
ret, printed = _do_run(cap_out, store, str(in_git_dir), opts)
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
assert expected in printed
|
assert expected in printed
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ def _run_try_repo(tempdir_factory, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
def test_try_repo_repo_only(cap_out, tempdir_factory):
|
def test_try_repo_repo_only(cap_out, tempdir_factory):
|
||||||
with mock.patch.object(time, 'time', return_value=0.0):
|
with mock.patch.object(time, 'monotonic', return_value=0.0):
|
||||||
_run_try_repo(tempdir_factory, verbose=True)
|
_run_try_repo(tempdir_factory, verbose=True)
|
||||||
start, config, rest = _get_out(cap_out)
|
start, config, rest = _get_out(cap_out)
|
||||||
assert start == ''
|
assert start == ''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue