From 3667de1d0fccc942e912dbc440da71c7de0d2398 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 2 Apr 2025 00:05:30 -0400 Subject: [PATCH] run_tests: fix running when cwd is not the root If you try running this from a subdir, then most of the tests fail because they assume they're running from the top of the source tree. Change all the tests to actually run there. For example: cd docs && ../run_tests Change-Id: I92e17476393a108e56b58e049193b9fd72c5b7ba Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/464841 Reviewed-by: Gavin Mak Tested-by: Mike Frysinger Commit-Queue: Mike Frysinger --- run_tests | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/run_tests b/run_tests index ef7c04b7..d64cc700 100755 --- a/run_tests +++ b/run_tests @@ -21,8 +21,6 @@ import subprocess import sys from typing import List -import pytest - ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) @@ -38,7 +36,11 @@ def run_pytest(argv: List[str]) -> int: if is_ci(): argv = ["-m", "not skip_cq"] + argv - return pytest.main(argv) + return subprocess.run( + [sys.executable, "-m", "pytest"] + argv, + check=False, + cwd=ROOT_DIR, + ).returncode def run_pytest_py38(argv: List[str]) -> int: @@ -57,6 +59,7 @@ def run_pytest_py38(argv: List[str]) -> int: ] + argv, check=False, + cwd=ROOT_DIR, ).returncode except FileNotFoundError: # Skip if the user doesn't have vpython from depot_tools. @@ -76,20 +79,25 @@ def run_black(): return subprocess.run( [sys.executable, "-m", "black", "--check", ROOT_DIR] + extra_programs, check=False, + cwd=ROOT_DIR, ).returncode def run_flake8(): """Returns the exit code from flake8.""" return subprocess.run( - [sys.executable, "-m", "flake8", ROOT_DIR], check=False + [sys.executable, "-m", "flake8", ROOT_DIR], + check=False, + cwd=ROOT_DIR, ).returncode def run_isort(): """Returns the exit code from isort.""" return subprocess.run( - [sys.executable, "-m", "isort", "--check", ROOT_DIR], check=False + [sys.executable, "-m", "isort", "--check", ROOT_DIR], + check=False, + cwd=ROOT_DIR, ).returncode