Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(566)

Unified Diff: presubmit_canned_checks.py

Issue 115516: Add new presubmit check RunPythonUnitTests. (Closed)
Patch Set: Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « PRESUBMIT.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: presubmit_canned_checks.py
diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py
index c1f9f166628e7dae82ee44460563a8fa067c2075..1b6d6465bdb254ff705426b5d210c996a084cbcf 100755
--- a/presubmit_canned_checks.py
+++ b/presubmit_canned_checks.py
@@ -118,3 +118,30 @@ def CheckTreeIsOpen(input_api, output_api, url, closed):
except IOError:
pass
return []
+
+
+def RunPythonUnitTests(input_api, output_api, unit_tests):
+ """Imports the unit_tests modules and run them."""
+ import unittest
+ tests_suite = []
+ test_loader = unittest.TestLoader()
+ def LoadTests(module_name):
+ module = __import__(module_name)
+ for part in module_name.split('.')[1:]:
+ module = getattr(module, part)
+ tests_suite.extend(test_loader.loadTestsFromModule(module)._tests)
+
+ outputs = []
+ for unit_test in unit_tests:
+ try:
+ LoadTests(unit_test)
+ except ImportError:
+ outputs.Append(output_api.PresubmitError("Failed to load %s" % unit_test))
+ raise
+
+ results = unittest.TextTestRunner(verbosity=0).run(unittest.TestSuite(
+ tests_suite))
+ if not results.wasSuccessful():
+ outputs.append(output_api.PresubmitError(
+ "%d unit tests failed." % (results.failures + results.errors)))
+ return outputs
« no previous file with comments | « PRESUBMIT.py ('k') | tests/presubmit_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698