From 78cd4161f0a264df89046b6324446b27011b0930 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sun, 29 Mar 2015 13:40:35 +0200 Subject: [PATCH] Don't use threads in this test I think test failures would've been ignored if there were some. Fixes #1401 --- tests/test_basic.py | 49 +++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/tests/test_basic.py b/tests/test_basic.py index 32a712bf..2fc6de2c 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1180,35 +1180,32 @@ def test_test_app_proper_environ(): assert rv.data == b'Foo SubDomain' -def test_exception_propagation(): - def apprunner(configkey): - app = flask.Flask(__name__) - app.config['LOGGER_HANDLER_POLICY'] = 'never' +@pytest.mark.parametrize('config_key', + ['TESTING', 'PROPAGATE_EXCEPTIONS', 'DEBUG', None]) +def test_exception_propagation(config_key): + app = flask.Flask(__name__) + app.config['LOGGER_HANDLER_POLICY'] = 'never' - @app.route('/') - def index(): - 1 // 0 - 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 + @app.route('/') + def index(): + 1 // 0 + c = app.test_client() - # we have to run this test in an isolated thread because 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 + if config_key is not None: + app.config[config_key] = True + with pytest.raises(Exception): + 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. - for config_key in 'TESTING', 'PROPAGATE_EXCEPTIONS', 'DEBUG', None: - t = Thread(target=apprunner, args=(config_key,)) - t.start() - t.join() - + while flask._request_ctx_stack.top is not None: + flask._request_ctx_stack.pop() + while flask._app_ctx_stack.top is not None: + flask._app_ctx_stack.pop() def test_max_content_length(): app = flask.Flask(__name__)