replace log_info_mock with pytest's caplog

This commit is contained in:
Anthony Sottile 2024-09-30 19:58:16 -04:00
parent e7cfc0d2cb
commit 1d2f1c0cce
3 changed files with 8 additions and 15 deletions

View file

@ -2,7 +2,6 @@ from __future__ import annotations
import functools
import io
import logging
import os.path
from unittest import mock
@ -203,12 +202,6 @@ def store(tempdir_factory):
yield Store(os.path.join(tempdir_factory.get(), '.pre-commit'))
@pytest.fixture
def log_info_mock():
with mock.patch.object(logging.getLogger('pre_commit'), 'info') as mck:
yield mck
class Fixture:
def __init__(self, stream: io.BytesIO) -> None:
self._stream = stream

View file

@ -240,16 +240,16 @@ def test_unknown_keys(store, caplog):
assert msg == 'Unexpected key(s) present on local => too-much: foo, hello'
def test_reinstall(tempdir_factory, store, log_info_mock):
def test_reinstall(tempdir_factory, store, caplog):
path = make_repo(tempdir_factory, 'python_hooks_repo')
config = make_config_from_repo(path)
_get_hook(config, store, 'foo')
# We print some logging during clone (1) + install (3)
assert log_info_mock.call_count == 4
log_info_mock.reset_mock()
assert len(caplog.record_tuples) == 4
caplog.clear()
# Reinstall on another run should not trigger another install
_get_hook(config, store, 'foo')
assert log_info_mock.call_count == 0
assert len(caplog.record_tuples) == 0
def test_control_c_control_c_on_install(tempdir_factory, store):

View file

@ -65,7 +65,7 @@ def test_store_init(store):
assert text_line in readme_contents
def test_clone(store, tempdir_factory, log_info_mock):
def test_clone(store, tempdir_factory, caplog):
path = git_dir(tempdir_factory)
with cwd(path):
git_commit()
@ -74,7 +74,7 @@ def test_clone(store, tempdir_factory, log_info_mock):
ret = store.clone(path, rev)
# Should have printed some stuff
assert log_info_mock.call_args_list[0][0][0].startswith(
assert caplog.record_tuples[0][-1].startswith(
'Initializing environment for ',
)
@ -118,7 +118,7 @@ def test_clone_when_repo_already_exists(store):
def test_clone_shallow_failure_fallback_to_complete(
store, tempdir_factory,
log_info_mock,
caplog,
):
path = git_dir(tempdir_factory)
with cwd(path):
@ -134,7 +134,7 @@ def test_clone_shallow_failure_fallback_to_complete(
ret = store.clone(path, rev)
# Should have printed some stuff
assert log_info_mock.call_args_list[0][0][0].startswith(
assert caplog.record_tuples[0][-1].startswith(
'Initializing environment for ',
)