from flask import Flask as _Flask from flask import Blueprint as _Blueprint if not hasattr(_Flask, 'template_test'): # model `template_test` -- introduced with flask-0.10 class Flask(_Flask): def template_test(self, name=None): def decorator(f): self.add_template_test(f, name=name) return f return decorator def add_template_test(self, f, name=None): self.jinja_env.tests[name or f.__name__] = f class Blueprint(_Blueprint): def app_template_test(self, name=None): def decorator(f): self.add_app_template_test(f, name=name) return f return decorator def add_app_template_test(self, f, name=None): def register_template(state): state.app.jinja_env.tests[name or f.__name__] = f self.record_once(register_template) else: Flask = _Flask Blueprint = _Blueprint del _Flask, _Blueprint