From ac296200eb73cf0e6e61cacfaf524cba3ce27677 Mon Sep 17 00:00:00 2001 From: "smut@google.com" Date: Thu, 24 Apr 2014 21:47:17 +0000 Subject: [PATCH] Adding custom environment variable support to presubmit_canned_checks.GetUnitTestsInDirectory I want to run Python unit tests as part of my presubmit, and those unit tests require PYTHONPATH to be set the way it would be set when the modules they test are running. Review URL: https://codereview.chromium.org/250693002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@265998 0039d316-1c4b-4281-b951-d872f2087c98 --- presubmit_canned_checks.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 10a8d273d..bd3c361f2 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -496,7 +496,7 @@ def CheckTreeIsOpen(input_api, output_api, return [] def GetUnitTestsInDirectory( - input_api, output_api, directory, whitelist=None, blacklist=None): + input_api, output_api, directory, whitelist=None, blacklist=None, env=None): """Lists all files in a directory and runs them. Doesn't recurse. It's mainly a wrapper for RunUnitTests. Use whitelist and blacklist to filter @@ -528,10 +528,10 @@ def GetUnitTestsInDirectory( 'Out of %d files, found none that matched w=%r, b=%r in directory %s' % (found, whitelist, blacklist, directory)) ] - return GetUnitTests(input_api, output_api, unit_tests) + return GetUnitTests(input_api, output_api, unit_tests, env) -def GetUnitTests(input_api, output_api, unit_tests): +def GetUnitTests(input_api, output_api, unit_tests, env=None): """Runs all unit tests in a directory. On Windows, sys.executable is used for unit tests ending with ".py". @@ -551,10 +551,13 @@ def GetUnitTests(input_api, output_api, unit_tests): cmd.append(unit_test) if input_api.verbose: cmd.append('--verbose') + kwargs = {'cwd': input_api.PresubmitLocalPath()} + if env: + kwargs['env'] = env results.append(input_api.Command( name=unit_test, cmd=cmd, - kwargs={'cwd': input_api.PresubmitLocalPath()}, + kwargs=kwargs, message=message_type)) return results