Flask Testing - How to retrieve variables that were passed to Jinja?
<p>In Flask, how can I test what variables were returned to a Jinja template with <code>render_template</code>?</p>

<pre><code>@app.route('/foo/'):
def foo():
    return render_template('foo.html', foo='bar')
</code></pre>

<p>In this example, I want to test that <code>foo</code> is equal to <code>"bar"</code>. </p>

<pre><code>import unittest
from app import app

class TestFoo(unittest.TestCase):
    def test_foo(self):
        with app.test_client() as c:
            r = c.get('/foo/')
            # Prove that the foo variable is equal to "bar"
</code></pre>

<p>How can I do this?</p>

<p>The best way will be to use something like that:</p>

<pre><code>self.assertTrue('Hello bar!' in r.body)
</code></pre>

<p>And in <code>foo.html</code>:</p>

<pre><code>&lt;div&gt;Hello {{ foo }}!&lt;/div&gt;
</code></pre>

<p>Of course I don't know structure of your html, so this example above is just a prototype.</p>

python flask