Skip to content

Commit 3f66498

Browse files
authored
Merge pull request #878 from jdufresne/resource-warning
Fix ResourceWarning that occur during tests
2 parents ba465d9 + ba383b4 commit 3f66498

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tests/test_utils.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,17 @@ def test_iter_keepopenfile(tmpdir):
268268
expected = list(map(str, range(10)))
269269
p = tmpdir.mkdir('testdir').join('testfile')
270270
p.write(os.linesep.join(expected))
271-
f = p.open()
272-
for e_line, a_line in zip(expected, click.utils.KeepOpenFile(f)):
273-
assert e_line == a_line.strip()
271+
with p.open() as f:
272+
for e_line, a_line in zip(expected, click.utils.KeepOpenFile(f)):
273+
assert e_line == a_line.strip()
274274

275275

276276
@pytest.mark.xfail(WIN and not PY2, reason='God knows ...')
277277
def test_iter_lazyfile(tmpdir):
278278
expected = list(map(str, range(10)))
279279
p = tmpdir.mkdir('testdir').join('testfile')
280280
p.write(os.linesep.join(expected))
281-
f = p.open()
282-
for e_line, a_line in zip(expected, click.utils.LazyFile(f.name)):
283-
assert e_line == a_line.strip()
281+
with p.open() as f:
282+
with click.utils.LazyFile(f.name) as lf:
283+
for e_line, a_line in zip(expected, lf):
284+
assert e_line == a_line.strip()

0 commit comments

Comments
 (0)