Skip to content
Myr

Added better test runner

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 4cb6eea · Browse files · 1 file+57 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+57 added−0 removed

  • other:+57 added−0 removed

1 file+57 added−0 removed

added:run-tests.py+57 added
1import sys2import unittest3from unittest.loader import TestLoader4from flask.testsuite import suite56common_prefix = suite.__module__ + '.'789def find_all_tests():10 suites = [suite()]11 while suites:12 s = suites.pop()13 try:14 suites.extend(s)15 except TypeError:16 yield s171819def find_all_tests_with_name():20 for testcase in find_all_tests():21 yield testcase, '%s.%s.%s' % (22 testcase.__class__.__module__,23 testcase.__class__.__name__,24 testcase._testMethodName25 )262728class BetterLoader(TestLoader):2930 def loadTestsFromName(self, name, module=None):31 if name == 'suite':32 return suite()33 for testcase, testname in find_all_tests_with_name():34 if testname == name:35 return testcase36 if testname.startswith(common_prefix):37 if testname[len(common_prefix):] == name:38 return testcase3940 all_results = []41 for testcase, testname in find_all_tests_with_name():42 if testname.endswith('.' + name):43 all_results.append((testcase, testname))4445 if len(all_results) == 1:46 return all_results[0][0]47 elif not len(all_results):48 error = 'could not find testcase "%s"' % name49 else:50 error = 'Too many matches: for "%s"\n%s' % \51 (name, '\n'.join(' - ' + n for c, n in all_results))5253 print >> sys.stderr, 'Error: %s' % error54 sys.exit(1)555657unittest.main(testLoader=BetterLoader(), defaultTest='suite')