title: Flask disable CSRF in unittest
body: <p>In my projects __init__.py I have this:</p>
  
  <pre><code>app = Flask(__name__)
  app.config.from_object('config')
  CsrfProtect(app)
  db = SQLAlchemy(app)
  </code></pre>
  
  <p>My development config file looks like:</p>
  
  <pre><code>import os
  basedir = os.path.abspath(os.path.dirname(__file__))
  
  DEBUG = True
  WTF_CSRF_ENABLED = True
  SECRET_KEY = 'supersecretkey'
  SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'project.db')
  SQLALCHEMY_TRACK_MODIFICATIONS = False
  </code></pre>
  
  <p>And in my unittest setUp I have this:</p>
  
  <pre><code>from project import app, db
  
  class ExampleTest(unittest.TestCase):
     def setUp(self):
          app.config['TESTING'] = True
          app.config['WTF_CSRF_ENABLED'] = False
          app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
          self.app = app.test_client()
          db.create_all()
  </code></pre>
  
  <p>In theory, setting WTF_CSRF_ENABLED to False here should prevent CSRF for the unit tests, however I'm still getting CSRF errors if I do a POST while unit testing. I think it is because I have already called CsrfProtect(app) while WTF_CSRF_ENABLED is True (when I import app, it is called). If I set WTF_CSRF_ENABLED = False in the config file, it works as expected.</p>
  
  <p>Is there anyway I can disable CSRF after it has already been enabled? Or am I barking up the wrong tree here?</p>