flask-testing
flask-testing copied to clipboard
How are the tests run?
The documentation does not specify how the tests are to be run. Perhaps this should be added.
- Bitbucket: https://bitbucket.org/danjac/flask-testing/issue/6
- Originally Reported By: Kiran Jonnalagadda
- Originally Created At: 2011-03-09 15:46:07
Hi,
Is there any documentation about that specific part ?
Best regards,
t00f
Original Comment By: Christophe Serafin
I'm wondering the same thing? Shouldn't they be run automatically before app launch if in debug mode?
You may also use discovery to run tests, please check out my Flask-Script management command example below:
@manager.command
def tests(verbosity=2):
"""Runs all application unit tests"""
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
project_root = os.path.dirname(os.path.relpath(__file__)) or '.'
tests = unittest.TestLoader().discover(project_root)
result = unittest.TextTestRunner(verbosity=verbosity).run(tests)
exit(int(not result.wasSuccessful()))
If you're using Python 2.6, you'll need to install unittest2 so that the discover function works.
Naturally, you may also place this in a separate run_tests.py script like this:
#!/usr/bin/env python
import sys
import os
if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest
def main():
project_root = os.path.dirname(os.path.relpath(__file__)) or '.'
tests = unittest.TestLoader().discover(project_root)
result = unittest.TextTestRunner(verbosity=2).run(tests)
exit(int(not result.wasSuccessful()))
if __name__ == '__main__':
main()
Ensure that your manage.py or run_tests.py is in the root of your project :smile:
Cheers Fotis