title: Templates when unit testing a Flask application
body: <p>I'm writing unit tests for a Flask application that has roughly the following organization:</p>
  
  <pre><code>/myapplication
      runner.py
      /myapplication
          __init__.py
      /special
          __init__.py
          views.py
          models.py
      /static
      /templates
          index.html
          /special
              index_special.html
      /tests
          __init__.py
          /special
              __init__.py
              test_special.py
  </code></pre>
  
  <p>In particular, I want to test that the <code>special</code> module works as expected. </p>
  
  <p>I have defined the following:</p>
  
  <ul>
  <li><p>in <code>special/views.py</code>:</p>
  
  <pre><code>mod = Blueprint('special', __name__, template_folder="templates")
  @mod.route('/standard')
  def info():
      return render_template('special/index_special.html')
  </code></pre></li>
  <li><p>in <code>myapplication/__init__.py</code>:</p>
  
  <pre><code>app = Flask(__name__)
  
  def register_blueprints(app):
       from special.views import mod as special_blueprint
       app.register_blueprint(special_blueprint, url_prefix='/special')
  
  register_blueprints(app)
  </code></pre></li>
  <li><p>in <code>myapplication/tests/test_special.py</code></p>
  
  <pre><code>class TestSpecial:
      @classmethod
      def create_app(cls):
          app = Flask(__name__)
          register_blueprints(app)
          return app
  
      @classmethod
      def setup_class(cls):
          cls.app = cls.create_app()
          cls.client = cls.app.test_client()
  
      def test_connect(self):
          r = self.client.get('/standard')
          assert r.status_code == 200
  </code></pre></li>
  </ul>
  
  <p>While the application itself works fine, the <code>test_connect</code> unit-test fails with a <code>TemplateNotFound: special/index_special.html</code> exception.</p>
  
  <p>How could I tell the tests where to find the corresponding templates ? Bypassing the rendering of templates using <a href="http://pythonhosted.org/Flask-Testing/" rel="nofollow">Flask-testing</a> is not really an option...</p>