Skip to content

Instantly share code, notes, and snippets.

@lost-theory
Created August 18, 2012 07:09
Show Gist options
  • Save lost-theory/3385009 to your computer and use it in GitHub Desktop.
Save lost-theory/3385009 to your computer and use it in GitHub Desktop.
mock render_template
from mock import patch #http://pypi.python.org/pypi/mock
import flask
import myapp
@patch('flask.templating._render', return_value='')
def test_mocked_render(mocked):
t = myapp.app.test_client()
print "mocked", repr(t.get("/").data)
print "was _render called?", mocked.called
def test_normal_render():
t = myapp.app.test_client()
print "normal", repr(t.get('/').data)
if __name__ == "__main__":
test_normal_render()
test_mocked_render()
test_normal_render()
#output:
'''
$ ../bin/python tests.py
normal '<html><head></head><body><p>stuff</p></body></html>'
mocked ''
was _render called? True
normal '<html><head></head><body><p>stuff</p></body></html>'
'''
@igiroux
Copy link

igiroux commented Sep 26, 2017

That was exactly what I was looking for and it worked well! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment