Test Flask render_template() context

前端 未结 4 962
滥情空心
滥情空心 2020-12-24 12:02

I have a Flask route that looks like this:

@app.route(\'/\')                                                                 
def home():                             


        
4条回答
  •  甜味超标
    2020-12-24 12:41

    My suggestion would be to take a look at the Flask documentation for testing.

    Using the docs as a guide you should be able to set up a test case that can check the contents of the response.

    import unittest
    import yourappname
    
    class MyAppTestCase(unittest.TestCase):
        def setUp(self):
            self.app = yourappname.app.test_client()
    
        def test_greeting(self):
            rv = self.app.get('/')
            self.assertIn('hello', rv.data)
    

    where yourappname is the name of your app/project.

提交回复
热议问题