Browse files

Some more cleanups in how the test runner is invoked

  • Loading branch information...
1 parent 367b254 commit e509d25d32965a8afd7ca98d67ee6f5a6af11cc8 @mitsuhiko mitsuhiko committed Aug 26, 2011
Showing with 27 additions and 12 deletions.
  1. +25 −6 flask/testsuite/__init__.py
  2. +2 −6 run-tests.py
View
31 flask/testsuite/__init__.py
@@ -21,6 +21,10 @@
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):
try:
return os.path.samefile(x, y)
@@ -35,19 +39,16 @@ def _samefile(x, y):
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():
+ """Yields all testsuites."""
for module in find_modules(__name__):
mod = import_string(module)
if hasattr(mod, 'suite'):
yield mod.suite()
def find_all_tests(suite):
+ """Yields all the tests and their names from a given suite."""
suites = [suite]
while suites:
s = suites.pop()
@@ -167,9 +168,27 @@ def loadTestsFromName(self, name, module=None):
return rv
+def setup_path():
+ add_to_path(os.path.abspath(os.path.join(
+ os.path.dirname(__file__), 'test_apps')))
+
+
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()
for other_suite in iter_suites():
suite.addTest(other_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
View
8 run-tests.py
@@ -1,6 +1,2 @@
-import unittest
-from flask.testsuite import BetterLoader
-try:
- unittest.main(testLoader=BetterLoader(), defaultTest='suite')
-except Exception, e:
- print 'Error: %s' % e
+from flask.testsuite import main
+main()

0 comments on commit e509d25

Please sign in to comment.