Flask -Test Template没有发现异常

时间:2015-07-28 09:54:32

标签: python flask nosetests flask-testing

我想测试一些路线但是当我运行nosetests时会写错误

  

“TemplateNotFound:main.html”

我的烧瓶测试课程中有render_templates = False

例如,我想测试此端点

  @users.route('/test', methods=['GET','POST'])
  def test():
    return render_template('main.html')

我使用 TestCase

创建了test.py文件
class TestConfig(object):
   DEBUG = False
   TESTING = True
   WTF_CSRF_ENABLED = False
   PRESERVE_CONTEXT_ON_EXCEPTION = False
   SECRET_KEY = "sekret_key"
   template_folder = "/home/project_name/templates"

class TestNotRenderTemplates(TestCase):

  render_templates = False

  def create_app(self):
     app = Flask(__name__)
     app = create_app(TestConfig)
     return app


  def test_assert_mytemplate_used(self):
     response = self.client.get("/u/test")
     self.assert_template_used('main.html')

0 个答案:

没有答案