summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2025-04-02 00:05:30 -0400
committerLUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com>2025-04-03 11:11:04 -0700
commit3667de1d0fccc942e912dbc440da71c7de0d2398 (patch)
tree496c699e2c4d8f7b49e3e099c2176cff86f6b18e
parent85ee1738e62741bb2fdec0581988c4eeb11712f1 (diff)
downloadgit-repo-3667de1d0fccc942e912dbc440da71c7de0d2398.tar.gz
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 <gavinmak@google.com> Tested-by: Mike Frysinger <vapier@google.com> Commit-Queue: Mike Frysinger <vapier@google.com>
-rwxr-xr-xrun_tests18
1 files 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
21import sys 21import sys
22from typing import List 22from typing import List
23 23
24import pytest
25
26 24
27ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) 25ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
28 26
@@ -38,7 +36,11 @@ def run_pytest(argv: List[str]) -> int:
38 if is_ci(): 36 if is_ci():
39 argv = ["-m", "not skip_cq"] + argv 37 argv = ["-m", "not skip_cq"] + argv
40 38
41 return pytest.main(argv) 39 return subprocess.run(
40 [sys.executable, "-m", "pytest"] + argv,
41 check=False,
42 cwd=ROOT_DIR,
43 ).returncode
42 44
43 45
44def run_pytest_py38(argv: List[str]) -> int: 46def run_pytest_py38(argv: List[str]) -> int:
@@ -57,6 +59,7 @@ def run_pytest_py38(argv: List[str]) -> int:
57 ] 59 ]
58 + argv, 60 + argv,
59 check=False, 61 check=False,
62 cwd=ROOT_DIR,
60 ).returncode 63 ).returncode
61 except FileNotFoundError: 64 except FileNotFoundError:
62 # Skip if the user doesn't have vpython from depot_tools. 65 # Skip if the user doesn't have vpython from depot_tools.
@@ -76,20 +79,25 @@ def run_black():
76 return subprocess.run( 79 return subprocess.run(
77 [sys.executable, "-m", "black", "--check", ROOT_DIR] + extra_programs, 80 [sys.executable, "-m", "black", "--check", ROOT_DIR] + extra_programs,
78 check=False, 81 check=False,
82 cwd=ROOT_DIR,
79 ).returncode 83 ).returncode
80 84
81 85
82def run_flake8(): 86def run_flake8():
83 """Returns the exit code from flake8.""" 87 """Returns the exit code from flake8."""
84 return subprocess.run( 88 return subprocess.run(
85 [sys.executable, "-m", "flake8", ROOT_DIR], check=False 89 [sys.executable, "-m", "flake8", ROOT_DIR],
90 check=False,
91 cwd=ROOT_DIR,
86 ).returncode 92 ).returncode
87 93
88 94
89def run_isort(): 95def run_isort():
90 """Returns the exit code from isort.""" 96 """Returns the exit code from isort."""
91 return subprocess.run( 97 return subprocess.run(
92 [sys.executable, "-m", "isort", "--check", ROOT_DIR], check=False 98 [sys.executable, "-m", "isort", "--check", ROOT_DIR],
99 check=False,
100 cwd=ROOT_DIR,
93 ).returncode 101 ).returncode
94 102
95 103