Skip to content

Commit 7555e11

Browse files
authored
Merge pull request #3314 from pre-commit/remove-log-info-mock
replace log_info_mock with pytest's caplog
2 parents 05e365f + 1d2f1c0 commit 7555e11

File tree

3 files changed

+8
-15
lines changed

3 files changed

+8
-15
lines changed

tests/conftest.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import functools
44
import io
5-
import logging
65
import os.path
76
from unittest import mock
87

@@ -203,12 +202,6 @@ def store(tempdir_factory):
203202
yield Store(os.path.join(tempdir_factory.get(), '.pre-commit'))
204203

205204

206-
@pytest.fixture
207-
def log_info_mock():
208-
with mock.patch.object(logging.getLogger('pre_commit'), 'info') as mck:
209-
yield mck
210-
211-
212205
class Fixture:
213206
def __init__(self, stream: io.BytesIO) -> None:
214207
self._stream = stream

tests/repository_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,16 @@ def test_unknown_keys(store, caplog):
240240
assert msg == 'Unexpected key(s) present on local => too-much: foo, hello'
241241

242242

243-
def test_reinstall(tempdir_factory, store, log_info_mock):
243+
def test_reinstall(tempdir_factory, store, caplog):
244244
path = make_repo(tempdir_factory, 'python_hooks_repo')
245245
config = make_config_from_repo(path)
246246
_get_hook(config, store, 'foo')
247247
# We print some logging during clone (1) + install (3)
248-
assert log_info_mock.call_count == 4
249-
log_info_mock.reset_mock()
248+
assert len(caplog.record_tuples) == 4
249+
caplog.clear()
250250
# Reinstall on another run should not trigger another install
251251
_get_hook(config, store, 'foo')
252-
assert log_info_mock.call_count == 0
252+
assert len(caplog.record_tuples) == 0
253253

254254

255255
def test_control_c_control_c_on_install(tempdir_factory, store):

tests/store_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def test_store_init(store):
6565
assert text_line in readme_contents
6666

6767

68-
def test_clone(store, tempdir_factory, log_info_mock):
68+
def test_clone(store, tempdir_factory, caplog):
6969
path = git_dir(tempdir_factory)
7070
with cwd(path):
7171
git_commit()
@@ -74,7 +74,7 @@ def test_clone(store, tempdir_factory, log_info_mock):
7474

7575
ret = store.clone(path, rev)
7676
# Should have printed some stuff
77-
assert log_info_mock.call_args_list[0][0][0].startswith(
77+
assert caplog.record_tuples[0][-1].startswith(
7878
'Initializing environment for ',
7979
)
8080

@@ -118,7 +118,7 @@ def test_clone_when_repo_already_exists(store):
118118

119119
def test_clone_shallow_failure_fallback_to_complete(
120120
store, tempdir_factory,
121-
log_info_mock,
121+
caplog,
122122
):
123123
path = git_dir(tempdir_factory)
124124
with cwd(path):
@@ -134,7 +134,7 @@ def fake_shallow_clone(self, *args, **kwargs):
134134
ret = store.clone(path, rev)
135135

136136
# Should have printed some stuff
137-
assert log_info_mock.call_args_list[0][0][0].startswith(
137+
assert caplog.record_tuples[0][-1].startswith(
138138
'Initializing environment for ',
139139
)
140140

0 commit comments

Comments
 (0)