Add testcase to demonstrate r.iter_lines() reentrancy issue
authorPriit Laes <plaes@plaes.org>
Sat, 7 Mar 2015 07:40:25 +0000 (09:40 +0200)
committerPriit Laes <plaes@plaes.org>
Sat, 7 Mar 2015 10:00:37 +0000 (12:00 +0200)
test_requests.py

index 07430a8e844f679b9e1b23720206290d9785372c..15406a22fccdd53c0f49ed13761656c1b1160f10 100755 (executable)
@@ -1052,6 +1052,23 @@ class RequestsTestCase(unittest.TestCase):
         assert 'application/json' in r.request.headers['Content-Type']
         assert {'life': 42} == r.json()['json']
 
+    def test_response_iter_lines(self):
+        r = requests.get(httpbin('stream/4'), stream=True)
+        assert r.status_code == 200
+
+        it = r.iter_lines()
+        next(it)
+        assert len(list(it)) == 3
+
+    @pytest.mark.xfail
+    def test_response_iter_lines_reentrant(self):
+        """Response.iter_lines() is not reentrant safe"""
+        r = requests.get(httpbin('stream/4'), stream=True)
+        assert r.status_code == 200
+
+        next(r.iter_lines())
+        assert len(list(r.iter_lines())) == 3
+
 
 class TestContentEncodingDetection(unittest.TestCase):