From 57cb42861d37eec074a729f33d1c5aa90be86b3f Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Thu, 30 Mar 2023 05:06:01 +0000 Subject: run_tests: Check flake8 This also gets enforced in CQ. Bug: b/267675342 Change-Id: I8ffcc5d583275072fd61ae65ae4214b36bfa59f3 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/366799 Tested-by: Gavin Mak Reviewed-by: Mike Frysinger Commit-Queue: Gavin Mak --- run_tests | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'run_tests') diff --git a/run_tests b/run_tests index 69ba2769..2d92cae3 100755 --- a/run_tests +++ b/run_tests @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Wrapper to run black and pytest with the right settings.""" +"""Wrapper to run linters and pytest with the right settings.""" import os import subprocess @@ -21,19 +21,31 @@ import sys import pytest +ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) + + def run_black(): - """Returns the exit code of running `black --check`.""" - dirpath = os.path.dirname(os.path.realpath(__file__)) + """Returns the exit code from black.""" + return subprocess.run( + [sys.executable, "-m", "black", "--check", ROOT_DIR], check=False + ).returncode + + +def run_flake8(): + """Returns the exit code from flake8.""" return subprocess.run( - [sys.executable, "-m", "black", "--check", dirpath], check=False + [sys.executable, "-m", "flake8", ROOT_DIR], check=False ).returncode def main(argv): """The main entry.""" - pytest_ret = pytest.main(argv) - black_ret = run_black() - return 0 if not black_ret and not pytest_ret else 1 + checks = ( + lambda: pytest.main(argv), + run_black, + run_flake8, + ) + return 0 if all(not c() for c in checks) else 1 if __name__ == "__main__": -- cgit v1.2.3-54-g00ecf