I'm using Flask-Script
to run tests on my application the important bit of my manage.py
file looks like this:
import unittest
from flask.ext.script import Manager
from project import app
manager = Manager(app)
@manager.command
def test():
"""Run unit tests."""
app.config.from_object('config.Test')
tests = unittest.TestLoader().discover('tests', pattern='*.py')
unittest.TextTestRunner(verbosity=1).run(tests)
But when I run python manage.py test
it tries to initialise the entire application so if, for example, I haven't set my environment variables it throws a KeyError
from my project's __init__.py
file like so:
File "project/__init__.py", line 19, in <module>
app.config.from_object(os.environ['PROJECT_SETTINGS'])
Or if I have set the environment variable I get an error about missing database tables.
Surely the app should only initialise once the tests are running and the configuration variables have been set in the test()
function.