Test Flask render_template() context

You can use the assert_template_used method of TestCase provided by flask-testing.

from flask.ext.testing import TestCase

class MyTest(TestCase):

    def create_app(self):
        return myflaskapp

    def test_greeting(self):
        self.app.get("https://stackoverflow.com/")
        self.assert_template_used('hello.html')
        self.assert_context("greeting", "hello")

The method create_app must provide your flask app.

Leave a Comment