1

I want to set up test database for Flask-Testing class, so tests do not affect my main database. I need test database being created each time I run my unittests testcase How can I do this?

I use Flask-Testing, Flask-SQLAlchemy, psycopg2

Privilegies to create database properly granted. So now I just have to figure out how perform this.

Please advice how can I do this?

1 Answer 1

3

Use different setting for production and testing purpose.

How to create flask app this way - http://flask.pocoo.org/docs/0.10/patterns/appfactories/#app-factories

UPD

Create base_setting.py for base settings, production_setting.py and testing_setting.py with diffrerent db settings and create app from one of them. - http://flask.pocoo.org/docs/0.10/config/#configuring-from-files

for example:

app = Flask(__name__)
app.config.from_pyfile('base')
app.config.from_envvar('YOURAPPLICATION_SETTINGS')

Don't forget to set YOURAPPLICATION_SETTINGS env

Sign up to request clarification or add additional context in comments.

1 Comment

Can you please post more detailed answer so I could accept it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.