forked from orbit-oss/flask
Switch away from using None as default value for the exception when tearing down a context.
When an exception has been handled when using the request / app context in a with statement, `sys.exc_info()` will still contain the exception information even though it has been handled already. The `__exit__` methods pass in `None` for the exception value in that case, which needs to be distinguisable from the default value for the `exc` parameter. Use a dedicated singleton sentinel value instead.
This commit is contained in:
parent
ec5811d0a1
commit
ec0d208bc1
4 changed files with 45 additions and 8 deletions
|
|
@ -48,6 +48,21 @@ def test_teardown_with_previous_exception():
|
|||
assert buffer == []
|
||||
assert buffer == [None]
|
||||
|
||||
def test_teardown_with_handled_exception():
|
||||
buffer = []
|
||||
app = flask.Flask(__name__)
|
||||
@app.teardown_request
|
||||
def end_of_request(exception):
|
||||
buffer.append(exception)
|
||||
|
||||
with app.test_request_context():
|
||||
assert buffer == []
|
||||
try:
|
||||
raise Exception('dummy')
|
||||
except Exception:
|
||||
pass
|
||||
assert buffer == [None]
|
||||
|
||||
def test_proper_test_request_context():
|
||||
app = flask.Flask(__name__)
|
||||
app.config.update(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue