Armin Ronacher avatar Armin Ronacher committed 0ed8627

Warn on None responses.

Comments (0)

Files changed (2)

         """Converts the return value from a view function to a real
         response object that is an instance of :attr:`response_class`.
-        The following types are allowd for `rv`:
+        The following types are allowed for `rv`:
         ======================= ===========================================
         :attr:`response_class`  the object is returned unchanged
         :param rv: the return value from the view function
+        if rv is None:
+            from warnings import warn
+            warn(Warning('View function did not return a response'),
+                 stacklevel=2)
+            return u''
         if isinstance(rv, self.response_class):
             return rv
         if isinstance(rv, basestring):


 import flask
 import unittest
 import tempfile
+import warnings
 example_path = os.path.join(os.path.dirname(__file__), '..', 'examples')
             assert flask.url_for('static', filename='index.html') \
                 == '/static/index.html'
+    def test_none_response(self):
+        warnings.filterwarnings('error', 'View function did not return')
+        app = flask.Flask(__name__)
+        @app.route('/')
+        def test():
+            return None
+        try:
+            app.test_client().get('/')
+        except Warning:
+            pass
+        else:
+            assert "Expected warning"
 class JSONTestCase(unittest.TestCase):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.