diff options
author | Mike Frysinger <vapier@google.com> | 2025-04-02 00:05:30 -0400 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2025-04-03 11:11:04 -0700 |
commit | 3667de1d0fccc942e912dbc440da71c7de0d2398 (patch) | |
tree | 496c699e2c4d8f7b49e3e099c2176cff86f6b18e | |
parent | 85ee1738e62741bb2fdec0581988c4eeb11712f1 (diff) | |
download | git-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-x | run_tests | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -21,8 +21,6 @@ import subprocess | |||
21 | import sys | 21 | import sys |
22 | from typing import List | 22 | from typing import List |
23 | 23 | ||
24 | import pytest | ||
25 | |||
26 | 24 | ||
27 | ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) | 25 | ROOT_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 | ||
44 | def run_pytest_py38(argv: List[str]) -> int: | 46 | def 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 | ||
82 | def run_flake8(): | 86 | def 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 | ||
89 | def run_isort(): | 95 | def 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 | ||