Skip to content
Myr

Warn on None responses.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent dc3f13d · Browse files · 2 files+20 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+20 added−1 removed

  • tests:+14 added−0 removed
  • other:+6 added−1 removed

2 files+20 added−1 removed

modified:tests/flask_tests.py+14 added
13 unmodified lines
14import sys15import flask16import unittest17import tempfile18import warnings192021example_path = os.path.join(os.path.dirname(__file__), '..', 'examples')22sys.path.append(os.path.join(example_path, 'flaskr'))
201 unmodified lines
224 with app.test_request_context():225 assert flask.url_for('static', filename='index.html') \226 == '/static/index.html'227228 def test_none_response(self):229 warnings.filterwarnings('error', 'View function did not return')230 app = flask.Flask(__name__)231 @app.route('/')232 def test():233 return None234 try:235 app.test_client().get('/')236 except Warning:237 pass238 else:239 assert "Expected warning"240241242class JSONTestCase(unittest.TestCase):243244 def test_jsonify(self):245 d = dict(a=23, b=42, c=[1, 2, 3])
85 unmodified lines
modified:flask.py+6 added-1 removed
685 unmodified lines
686 def make_response(self, rv):687 """Converts the return value from a view function to a real688 response object that is an instance of :attr:`response_class`.689690 The following types are allowd for `rv`:690 The following types are allowed for `rv`:691692 ======================= ===========================================693 :attr:`response_class` the object is returned unchanged694 :class:`str` a response object is created with the
7 unmodified lines
702 ======================= ===========================================703704 :param rv: the return value from the view function705 """706 if rv is None:707 from warnings import warn708 warn(Warning('View function did not return a response'),709 stacklevel=2)710 return u''711 if isinstance(rv, self.response_class):712 return rv713 if isinstance(rv, basestring):714 return self.response_class(rv)
92 unmodified lines