Revert "Don't use threads in this test"

This reverts commit 78cd4161f0.
This commit is contained in:
Markus Unterwaditzer 2015-03-29 23:03:38 +02:00
parent 86e8267eb9
commit 1577e1386e

View file

@ -1180,32 +1180,35 @@ def test_test_app_proper_environ():
assert rv.data == b'Foo SubDomain' assert rv.data == b'Foo SubDomain'
@pytest.mark.parametrize('config_key', def test_exception_propagation():
['TESTING', 'PROPAGATE_EXCEPTIONS', 'DEBUG', None]) def apprunner(configkey):
def test_exception_propagation(config_key): app = flask.Flask(__name__)
app = flask.Flask(__name__) app.config['LOGGER_HANDLER_POLICY'] = 'never'
app.config['LOGGER_HANDLER_POLICY'] = 'never'
@app.route('/') @app.route('/')
def index(): def index():
1 // 0 1 // 0
c = app.test_client() c = app.test_client()
if config_key is not None:
app.config[config_key] = True
try:
c.get('/')
except Exception:
pass
else:
assert False, 'expected exception'
else:
assert c.get('/').status_code == 500
if config_key is not None: # we have to run this test in an isolated thread because if the
app.config[config_key] = True # debug flag is set to true and an exception happens the context is
with pytest.raises(Exception): # not torn down. This causes other tests that run after this fail
c.get('/')
else:
assert c.get('/').status_code == 500
# If the debug flag is set to true and an exception happens the context
# is not torn down. This causes other tests that run after this fail
# when they expect no exception on the stack. # when they expect no exception on the stack.
while flask._request_ctx_stack.top is not None: for config_key in 'TESTING', 'PROPAGATE_EXCEPTIONS', 'DEBUG', None:
flask._request_ctx_stack.pop() t = Thread(target=apprunner, args=(config_key,))
while flask._app_ctx_stack.top is not None: t.start()
flask._app_ctx_stack.pop() t.join()
def test_max_content_length(): def test_max_content_length():
app = flask.Flask(__name__) app = flask.Flask(__name__)