Browse Source

Some more cleanups in how the test runner is invoked

pull/309/head
Armin Ronacher 13 years ago
parent
commit
e509d25d32
  1. 31
      flask/testsuite/__init__.py
  2. 8
      run-tests.py

31
flask/testsuite/__init__.py

@ -21,6 +21,10 @@ from werkzeug.utils import import_string, find_modules
def add_to_path(path): def add_to_path(path):
"""Adds an entry to sys.path_info if it's not already there."""
if not os.path.isdir(path):
raise RuntimeError('Tried to add nonexisting path')
def _samefile(x, y): def _samefile(x, y):
try: try:
return os.path.samefile(x, y) return os.path.samefile(x, y)
@ -35,12 +39,8 @@ def add_to_path(path):
sys.path.append(path) sys.path.append(path)
def setup_paths():
add_to_path(os.path.abspath(os.path.join(
os.path.dirname(__file__), 'test_apps')))
def iter_suites(): def iter_suites():
"""Yields all testsuites."""
for module in find_modules(__name__): for module in find_modules(__name__):
mod = import_string(module) mod = import_string(module)
if hasattr(mod, 'suite'): if hasattr(mod, 'suite'):
@ -48,6 +48,7 @@ def iter_suites():
def find_all_tests(suite): def find_all_tests(suite):
"""Yields all the tests and their names from a given suite."""
suites = [suite] suites = [suite]
while suites: while suites:
s = suites.pop() s = suites.pop()
@ -167,9 +168,27 @@ class BetterLoader(unittest.TestLoader):
return rv return rv
def setup_path():
add_to_path(os.path.abspath(os.path.join(
os.path.dirname(__file__), 'test_apps')))
def suite(): def suite():
setup_paths() """A testsuite that has all the Flask tests. You can use this
function to integrate the Flask tests into your own testsuite
in case you want to test that monkeypatches to Flask do not
break it.
"""
setup_path()
suite = unittest.TestSuite() suite = unittest.TestSuite()
for other_suite in iter_suites(): for other_suite in iter_suites():
suite.addTest(other_suite) suite.addTest(other_suite)
return suite return suite
def main():
"""Runs the testsuite as command line application."""
try:
unittest.main(testLoader=BetterLoader(), defaultTest='suite')
except Exception, e:
print 'Error: %s' % e

8
run-tests.py

@ -1,6 +1,2 @@
import unittest from flask.testsuite import main
from flask.testsuite import BetterLoader main()
try:
unittest.main(testLoader=BetterLoader(), defaultTest='suite')
except Exception, e:
print 'Error: %s' % e

Loading…
Cancel
Save