From ab5e93bf18a0459487a5ee56cf4e5ce41b07283b Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 19 Feb 2024 03:25:40 -0500 Subject: [PATCH] Fix ResourceWarnings in tests. --- tests/test_io.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_io.py b/tests/test_io.py index 4fde027..b8e0b64 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -562,12 +562,15 @@ def test_write(self): # pylint: disable=R0201 content1 = StringIO("Iñtërnâtiônàližætiøn") assert 20 == io.write(StringIO(), content1) content1.seek(0) - assert 20 == io.write(TemporaryFile(), content1) + with TemporaryFile() as tf: + assert 20 == io.write(tf, content1) content2 = io.IterStringIO(iter("Hello World")) - assert 12 == io.write(TemporaryFile(), content2, chunksize=2) + with TemporaryFile() as tf: + assert 12 == io.write(tf, content2, chunksize=2) # pylint: disable=E1101 responses.add(responses.GET, url=url, body=body) r = requests.get(url, stream=True) # pylint: disable=C0103 - assert 55 == io.write(TemporaryFile(), r.iter_content) + with TemporaryFile() as tf: + assert 55 == io.write(tf, r.iter_content)