Skip to content
Myr

Fix ResourceWarning that occur during tests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Appear as: ResourceWarning: unclosed file ... Always close a file explicitly. Use a context manager to make this simpler.

authored by Jon Dufresne · committed by Jon Dufresne · parent b471d34 · Browse files · 1 file+7 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−6 removed

  • tests:+7 added−6 removed

1 file+7 added−6 removed

modified:tests/test_utils.py+7 added-6 removed
266 unmodified lines
267def test_iter_keepopenfile(tmpdir):268 expected = list(map(str, range(10)))269 p = tmpdir.mkdir('testdir').join('testfile')270 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()274275276@pytest.mark.xfail(WIN and not PY2, reason='God knows ...')277def test_iter_lazyfile(tmpdir):278 expected = list(map(str, range(10)))279 p = tmpdir.mkdir('testdir').join('testfile')280 p.write(os.linesep.join(expected))281 with p.open() as f: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()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()