@@ -42,10 +42,12 @@ def test_autoupdate_up_to_date_repo(up_to_date_repo, in_tmpdir, store):
4242 config = make_config_from_repo (up_to_date_repo , check = False )
4343 write_config ('.' , config )
4444
45- before = open (C .CONFIG_FILE ).read ()
45+ with open (C .CONFIG_FILE ) as f :
46+ before = f .read ()
4647 assert '^$' not in before
4748 ret = autoupdate (Runner ('.' , C .CONFIG_FILE ), store , tags_only = False )
48- after = open (C .CONFIG_FILE ).read ()
49+ with open (C .CONFIG_FILE ) as f :
50+ after = f .read ()
4951 assert ret == 0
5052 assert before == after
5153
@@ -68,9 +70,11 @@ def test_autoupdate_old_revision_broken(tempdir_factory, in_tmpdir, store):
6870
6971 config ['rev' ] = rev
7072 write_config ('.' , config )
71- before = open (C .CONFIG_FILE ).read ()
73+ with open (C .CONFIG_FILE ) as f :
74+ before = f .read ()
7275 ret = autoupdate (Runner ('.' , C .CONFIG_FILE ), store , tags_only = False )
73- after = open (C .CONFIG_FILE ).read ()
76+ with open (C .CONFIG_FILE ) as f :
77+ after = f .read ()
7478 assert ret == 0
7579 assert before != after
7680 assert update_rev in after
@@ -106,9 +110,11 @@ def test_autoupdate_out_of_date_repo(out_of_date_repo, in_tmpdir, store):
106110 )
107111 write_config ('.' , config )
108112
109- before = open (C .CONFIG_FILE ).read ()
113+ with open (C .CONFIG_FILE ) as f :
114+ before = f .read ()
110115 ret = autoupdate (Runner ('.' , C .CONFIG_FILE ), store , tags_only = False )
111- after = open (C .CONFIG_FILE ).read ()
116+ with open (C .CONFIG_FILE ) as f :
117+ after = f .read ()
112118 assert ret == 0
113119 assert before != after
114120 # Make sure we don't add defaults
@@ -128,10 +134,12 @@ def test_autoupdate_out_of_date_repo_with_correct_repo_name(
128134 write_config ('.' , config )
129135
130136 runner = Runner ('.' , C .CONFIG_FILE )
131- before = open (C .CONFIG_FILE ).read ()
137+ with open (C .CONFIG_FILE ) as f :
138+ before = f .read ()
132139 repo_name = 'file://{}' .format (out_of_date_repo .path )
133140 ret = autoupdate (runner , store , tags_only = False , repos = (repo_name ,))
134- after = open (C .CONFIG_FILE ).read ()
141+ with open (C .CONFIG_FILE ) as f :
142+ after = f .read ()
135143 assert ret == 0
136144 assert before != after
137145 assert out_of_date_repo .head_rev in after
@@ -148,10 +156,12 @@ def test_autoupdate_out_of_date_repo_with_wrong_repo_name(
148156 write_config ('.' , config )
149157
150158 runner = Runner ('.' , C .CONFIG_FILE )
151- before = open (C .CONFIG_FILE ).read ()
159+ with open (C .CONFIG_FILE ) as f :
160+ before = f .read ()
152161 # It will not update it, because the name doesn't match
153162 ret = autoupdate (runner , store , tags_only = False , repos = ('dne' ,))
154- after = open (C .CONFIG_FILE ).read ()
163+ with open (C .CONFIG_FILE ) as f :
164+ after = f .read ()
155165 assert ret == 0
156166 assert before == after
157167
@@ -171,7 +181,8 @@ def test_does_not_reformat(in_tmpdir, out_of_date_repo, store):
171181 f .write (config )
172182
173183 autoupdate (Runner ('.' , C .CONFIG_FILE ), store , tags_only = False )
174- after = open (C .CONFIG_FILE ).read ()
184+ with open (C .CONFIG_FILE ) as f :
185+ after = f .read ()
175186 expected = fmt .format (out_of_date_repo .path , out_of_date_repo .head_rev )
176187 assert after == expected
177188
@@ -200,7 +211,8 @@ def test_loses_formatting_when_not_detectable(
200211 f .write (config )
201212
202213 autoupdate (Runner ('.' , C .CONFIG_FILE ), store , tags_only = False )
203- after = open (C .CONFIG_FILE ).read ()
214+ with open (C .CONFIG_FILE ) as f :
215+ after = f .read ()
204216 expected = (
205217 'repos:\n '
206218 '- repo: {}\n '
@@ -225,7 +237,8 @@ def test_autoupdate_tagged_repo(tagged_repo, in_tmpdir, store):
225237
226238 ret = autoupdate (Runner ('.' , C .CONFIG_FILE ), store , tags_only = False )
227239 assert ret == 0
228- assert 'v1.2.3' in open (C .CONFIG_FILE ).read ()
240+ with open (C .CONFIG_FILE ) as f :
241+ assert 'v1.2.3' in f .read ()
229242
230243
231244@pytest .fixture
@@ -243,7 +256,8 @@ def test_autoupdate_tags_only(tagged_repo_with_more_commits, in_tmpdir, store):
243256
244257 ret = autoupdate (Runner ('.' , C .CONFIG_FILE ), store , tags_only = True )
245258 assert ret == 0
246- assert 'v1.2.3' in open (C .CONFIG_FILE ).read ()
259+ with open (C .CONFIG_FILE ) as f :
260+ assert 'v1.2.3' in f .read ()
247261
248262
249263@pytest .fixture
@@ -282,9 +296,11 @@ def test_autoupdate_hook_disappearing_repo(
282296 )
283297 write_config ('.' , config )
284298
285- before = open (C .CONFIG_FILE ).read ()
299+ with open (C .CONFIG_FILE ) as f :
300+ before = f .read ()
286301 ret = autoupdate (Runner ('.' , C .CONFIG_FILE ), store , tags_only = False )
287- after = open (C .CONFIG_FILE ).read ()
302+ with open (C .CONFIG_FILE ) as f :
303+ after = f .read ()
288304 assert ret == 1
289305 assert before == after
290306
0 commit comments