Improved the logic in which tests are found

This commit is contained in:
Armin Ronacher 2011-08-26 11:59:52 +01:00
parent 0851d956b3
commit 29b7efa36b

View file

@ -37,21 +37,21 @@ class BetterLoader(TestLoader):
if testname[len(common_prefix):] == name: if testname[len(common_prefix):] == name:
return testcase return testcase
all_results = [] all_tests = []
for testcase, testname in find_all_tests_with_name(): for testcase, testname in find_all_tests_with_name():
if testname.endswith('.' + name): if testname.endswith('.' + name) or ('.' + name + '.') in testname:
all_results.append((testcase, testname)) all_tests.append(testcase)
if len(all_results) == 1: if not all_tests:
return all_results[0][0] print >> sys.stderr, 'Error: could not find test case for "%s"' % name
elif not len(all_results): sys.exit(1)
error = 'could not find testcase "%s"' % name
else:
error = 'Too many matches: for "%s"\n%s' % \
(name, '\n'.join(' - ' + n for c, n in all_results))
print >> sys.stderr, 'Error: %s' % error if len(all_tests) == 1:
sys.exit(1) return all_tests[0]
rv = unittest.TestSuite()
for test in all_tests:
rv.addTest(test)
return rv
unittest.main(testLoader=BetterLoader(), defaultTest='suite') unittest.main(testLoader=BetterLoader(), defaultTest='suite')