Skip to content
Myr

fix contextlib.closing bug for sessions where content is not consumed (issue #2593)

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

authored by colin · committed by colin · parent 3c850b3 · Browse files · 2 files+26 added−0 removed
This commit

State

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

Diff stats

2 files+26 added−0 removed

  • other:+26 added−0 removed

2 files+26 added−0 removed

modified:requests/models.py+3 added
840 unmodified lines
841 called the underlying ``raw`` object must not be accessed again.842843 *Note: Should not normally need to be called explicitly.*844 """845 if not self._content_consumed:846 return self.raw.close()847848 return self.raw.release_conn()
modified:test_requests.py+23 added
7 unmodified lines
8import os9import pickle10import unittest11import collections12import contextlib13import random1415import io16import requests17import pytest
1235 unmodified lines
1253 assert frozenset(cid.keys()) == keyset1254 assert frozenset(cid) == keyset125512561257class TestSessionContextClosing(unittest.TestCase):12581259 def _perform_session_without_consuming(self):1260 session = requests.Session()12611262 urls = [1263 'http://reddit.com',1264 'http://github.com',1265 'http://bitbucket.org',1266 ]12671268 for _ in range(25):1269 with contextlib.closing(session.get(random.choice(urls), stream=True)) as r:1270 pass12711272 return "OK"12731274 def test_stream_session_content_not_consumed(self):1275 self.assertEqual(self._perform_session_without_consuming(), "OK")127612771278class UtilsTestCase(unittest.TestCase):12791280 def test_super_len_io_streams(self):1281 """ Ensures that we properly deal with different kinds of IO streams. """
380 unmodified lines