Skip to content

Commit

Permalink
Close attachment stream at end of test
Browse files Browse the repository at this point in the history
This avoids a warning with `-W default`:

ResourceWarning: unclosed file <_io.BufferedRandom name=14>
  • Loading branch information
jwhitlock committed Mar 23, 2022
1 parent 8738325 commit 1814229
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion emails/tests/views_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,9 @@ def get_name_and_stream(self, message):
"""Get the first attachment's filename and data stream from a message."""
for part in message.walk():
if part.is_attachment():
return _get_attachment(part)
name, stream = _get_attachment(part)
self.addCleanup(stream.close)
return name, stream
return None, None

def test_short_attachment(self):
Expand Down

0 comments on commit 1814229

Please sign in to comment.