diff options
author | Jon Dufresne <jon.dufresne@gmail.com> | 2017-10-17 18:46:25 -0700 |
---|---|---|
committer | Jon Dufresne <jon.dufresne@gmail.com> | 2017-10-17 18:46:25 -0700 |
commit | ba383b4faae0dd1e86195f42b15edcfaebe0d2d0 (patch) | |
tree | c5307903d6b3e50fb6034d7171c8747823a583c2 /tests/test_utils.py | |
parent | b471d346e93b818d7c8a87d8cee9e0705435ac19 (diff) | |
download | click-ba383b4faae0dd1e86195f42b15edcfaebe0d2d0.tar.gz |
Fix ResourceWarning that occur during tests
Appear as:
ResourceWarning: unclosed file ...
Always close a file explicitly. Use a context manager to make this
simpler.
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r-- | tests/test_utils.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py index 88923ad..98ac6e1 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -268,9 +268,9 @@ def test_iter_keepopenfile(tmpdir): expected = list(map(str, range(10))) p = tmpdir.mkdir('testdir').join('testfile') p.write(os.linesep.join(expected)) - f = p.open() - for e_line, a_line in zip(expected, click.utils.KeepOpenFile(f)): - assert e_line == a_line.strip() + with p.open() as f: + for e_line, a_line in zip(expected, click.utils.KeepOpenFile(f)): + assert e_line == a_line.strip() @pytest.mark.xfail(WIN and not PY2, reason='God knows ...') @@ -278,6 +278,7 @@ def test_iter_lazyfile(tmpdir): expected = list(map(str, range(10))) p = tmpdir.mkdir('testdir').join('testfile') p.write(os.linesep.join(expected)) - f = p.open() - for e_line, a_line in zip(expected, click.utils.LazyFile(f.name)): - assert e_line == a_line.strip() + with p.open() as f: + with click.utils.LazyFile(f.name) as lf: + for e_line, a_line in zip(expected, lf): + assert e_line == a_line.strip() |