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:
Martijn Pieters 2015-03-23 15:17:19 +00:00
parent ec5811d0a1
commit ec0d208bc1
4 changed files with 45 additions and 8 deletions

View file

@ -78,6 +78,21 @@ def test_app_tearing_down_with_previous_exception():
assert cleanup_stuff == [None]
def test_app_tearing_down_with_handled_exception():
cleanup_stuff = []
app = flask.Flask(__name__)
@app.teardown_appcontext
def cleanup(exception):
cleanup_stuff.append(exception)
with app.app_context():
try:
raise Exception('dummy')
except Exception:
pass
assert cleanup_stuff == [None]
def test_custom_app_ctx_globals_class():
class CustomRequestGlobals(object):
def __init__(self):