flask-testing icon indicating copy to clipboard operation
flask-testing copied to clipboard

How are the tests run?

Open rduplain opened this issue 13 years ago • 4 comments
trafficstars

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

rduplain avatar Feb 29 '12 16:02 rduplain

Hi,

Is there any documentation about that specific part ?

Best regards,

t00f


Original Comment By: Christophe Serafin

rduplain avatar Feb 29 '12 16:02 rduplain

Issue #5 was marked as a duplicate of this issue.


Original Comment By: Kiran Jonnalagadda

rduplain avatar Feb 29 '12 16:02 rduplain

I'm wondering the same thing? Shouldn't they be run automatically before app launch if in debug mode?

dalanmiller avatar Jul 20 '12 02:07 dalanmiller

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

fgimian avatar Feb 20 '14 09:02 fgimian