Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7555e11

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

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
importfunctools
44
importio
5-
importlogging
65
importos.path
76
fromunittestimportmock
87

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

205204

206-
@pytest.fixture
207-
deflog_info_mock():
208-
withmock.patch.object(logging.getLogger('pre_commit'),'info')asmck:
209-
yieldmck
210-
211-
212205
classFixture:
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
assertmsg=='Unexpected key(s) present on local => too-much: foo, hello'
241241

242242

243-
deftest_reinstall(tempdir_factory,store,log_info_mock):
243+
deftest_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-
assertlog_info_mock.call_count==4
249-
log_info_mock.reset_mock()
248+
assertlen(caplog.record_tuples)==4
249+
caplog.clear()
250250
# Reinstall on another run should not trigger another install
251251
_get_hook(config,store,'foo')
252-
assertlog_info_mock.call_count==0
252+
assertlen(caplog.record_tuples)==0
253253

254254

255255
deftest_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
asserttext_lineinreadme_contents
6666

6767

68-
deftest_clone(store,tempdir_factory,log_info_mock):
68+
deftest_clone(store,tempdir_factory,caplog):
6969
path=git_dir(tempdir_factory)
7070
withcwd(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-
assertlog_info_mock.call_args_list[0][0][0].startswith(
77+
assertcaplog.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
deftest_clone_shallow_failure_fallback_to_complete(
120120
store,tempdir_factory,
121-
log_info_mock,
121+
caplog,
122122
):
123123
path=git_dir(tempdir_factory)
124124
withcwd(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-
assertlog_info_mock.call_args_list[0][0][0].startswith(
137+
assertcaplog.record_tuples[0][-1].startswith(
138138
'Initializing environment for ',
139139
)
140140

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp