Skip to content
Myr

The test client now properly pops response contexts on __exit__

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

authored by Armin Ronacher · committed by Armin Ronacher · parent c8ec453 · Browse files · 4 files+48 added−4 removed
This commit

State

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

Diff stats

4 files+48 added−4 removed

  • other:+48 added−4 removed

4 files+48 added−4 removed

modified:docs/upgrading.rst+5 added
34 unmodified lines
35longer have to handle that error to avoid an internal server error showing36up for the user. If you were catching this down explicitly in the past37as `ValueError` you will need to change this.3839Due to a bug in the test client Flask 0.7 did not trigger teardown40handlers when the test client was used in a with statement. This was41since fixed but might require some changes in your testsuites if you42relied on this behavior.4344Version 0.745-----------4647In Flask 0.7 we cleaned up the code base internally a lot and did some
277 unmodified lines
modified:flask/testsuite/testing.py+32 added
124 unmodified lines
125 pass126 else:127 raise AssertionError('some kind of exception expected')128129 def test_reuse_client(self):130 app = flask.Flask(__name__)131 c = app.test_client()132133 with c:134 self.assert_equal(c.get('/').status_code, 404)135136 with c:137 self.assert_equal(c.get('/').status_code, 404)138139 def test_test_client_calls_teardown_handlers(self):140 app = flask.Flask(__name__)141 called = []142 @app.teardown_request143 def remember(error):144 called.append(error)145146 with app.test_client() as c:147 self.assert_equal(called, [])148 c.get('/')149 self.assert_equal(called, [])150 self.assert_equal(called, [None])151152 del called[:]153 with app.test_client() as c:154 self.assert_equal(called, [])155 c.get('/')156 self.assert_equal(called, [])157 c.get('/')158 self.assert_equal(called, [None])159 self.assert_equal(called, [None, None])160161162def suite():163 suite = unittest.TestSuite()164 suite.addTest(unittest.makeSuite(TestToolsTestCase))165 return suite
modified:flask/testing.py+9 added-4 removed
84 unmodified lines
85 headers = resp.get_wsgi_headers(c.request.environ)86 self.cookie_jar.extract_wsgi(c.request.environ, headers)8788 def open(self, *args, **kwargs):89 if self.context_preserved:90 _request_ctx_stack.pop()91 self.context_preserved = False89 self._pop_reqctx_if_necessary()90 kwargs.setdefault('environ_overrides', {}) \91 ['flask._preserve_context'] = self.preserve_context9293 as_tuple = kwargs.pop('as_tuple', False)
17 unmodified lines
111 return self112113 def __exit__(self, exc_type, exc_value, tb):114 self.preserve_context = False115 self._pop_reqctx_if_necessary()116117 def _pop_reqctx_if_necessary(self):118 if self.context_preserved:119 # we have to use _request_ctx_stack.top.pop instead of120 # _request_ctx_stack.pop since we want teardown handlers121 # to be executed.118 _request_ctx_stack.pop()122 _request_ctx_stack.top.pop()123 self.context_preserved = False
modified:CHANGES+2 added
38 unmodified lines
39 variable as well as ``SERVER_NAME`` are now properly used by the test client40 as defaults.41- Added :attr:`flask.views.View.decorators` to support simpler decorating of42 pluggable (class based) views.43- Fixed an issue where the test client if used with the with statement did not44 trigger the execution of the teardown handlers.4546Version 0.7.347-------------48
238 unmodified lines