forked from orbit-oss/flask
Test that we're not leaking a request context in the testsuite, fixed a leak
This commit is contained in:
parent
001a5128d8
commit
f051939d8b
1 changed files with 24 additions and 16 deletions
|
|
@ -96,7 +96,15 @@ def emits_module_deprecation_warning(f):
|
||||||
|
|
||||||
|
|
||||||
class FlaskTestCase(unittest.TestCase):
|
class FlaskTestCase(unittest.TestCase):
|
||||||
pass
|
|
||||||
|
def ensure_clean_request_context(self):
|
||||||
|
# make sure we're not leaking a request context since we are
|
||||||
|
# testing flask internally in debug mode in a few cases
|
||||||
|
self.assertEqual(flask._request_ctx_stack.top, None)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
unittest.TestCase.tearDown(self)
|
||||||
|
self.ensure_clean_request_context()
|
||||||
|
|
||||||
|
|
||||||
class ContextTestCase(FlaskTestCase):
|
class ContextTestCase(FlaskTestCase):
|
||||||
|
|
@ -1881,23 +1889,23 @@ class LoggingTestCase(FlaskTestCase):
|
||||||
@app.route('/exc')
|
@app.route('/exc')
|
||||||
def exc():
|
def exc():
|
||||||
1/0
|
1/0
|
||||||
c = app.test_client()
|
|
||||||
|
|
||||||
with catch_stderr() as err:
|
with app.test_client() as c:
|
||||||
c.get('/')
|
with catch_stderr() as err:
|
||||||
out = err.getvalue()
|
c.get('/')
|
||||||
assert 'WARNING in flask_tests [' in out
|
out = err.getvalue()
|
||||||
assert 'flask_tests.py' in out
|
assert 'WARNING in flask_tests [' in out
|
||||||
assert 'the standard library is dead' in out
|
assert 'flask_tests.py' in out
|
||||||
assert 'this is a debug statement' in out
|
assert 'the standard library is dead' in out
|
||||||
|
assert 'this is a debug statement' in out
|
||||||
|
|
||||||
with catch_stderr() as err:
|
with catch_stderr() as err:
|
||||||
try:
|
try:
|
||||||
c.get('/exc')
|
c.get('/exc')
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
assert False, 'debug log ate the exception'
|
assert False, 'debug log ate the exception'
|
||||||
|
|
||||||
def test_exception_logging(self):
|
def test_exception_logging(self):
|
||||||
out = StringIO()
|
out = StringIO()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue