How to setup testing script in Flask with SQLite? How to setup testing script in Flask with SQLite? flask flask

How to setup testing script in Flask with SQLite?


Omigod I figured it out. I was setting the wrong key for the database URI. It should be: app.config['SQLALCHEMY_DATABASE_URI'] = self.db_uri.

So everything is fine. Just do:

class UserTest(unittest.TestCase):    def setUp(self):        self.db_uri = 'sqlite:///' + os.path.join(basedir, 'test.db')        app.config['TESTING'] = True        app.config['WTF_CSRF_ENABLED'] = False        app.config['SQLALCHEMY_DATABASE_URI'] = self.db_uri        self.app = app.test_client()        db.create_all()

and everything works as intended.

I checked what was going on by putting a break-point in the tests and seeing what app.config was -- and I saw that there was both a SQL_ALCHEMY_DATABASE_URI key (which doesn't do anything and I was setting) and a SQLALCHEMY_DATABASE_URI key (this is the one that matters).