Created
August 18, 2012 07:09
-
-
Save lost-theory/3385009 to your computer and use it in GitHub Desktop.
mock render_template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>' | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That was exactly what I was looking for and it worked well! Thank you!