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>
This commit is contained in:
Mike Frysinger 2025-04-02 00:05:30 -04:00 committed by LUCI
parent 85ee1738e6
commit 3667de1d0f

View File

@ -21,8 +21,6 @@ import subprocess
import sys import sys
from typing import List from typing import List
import pytest
ROOT_DIR = os.path.dirname(os.path.realpath(__file__)) ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
@ -38,7 +36,11 @@ def run_pytest(argv: List[str]) -> int:
if is_ci(): if is_ci():
argv = ["-m", "not skip_cq"] + argv 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: def run_pytest_py38(argv: List[str]) -> int:
@ -57,6 +59,7 @@ def run_pytest_py38(argv: List[str]) -> int:
] ]
+ argv, + argv,
check=False, check=False,
cwd=ROOT_DIR,
).returncode ).returncode
except FileNotFoundError: except FileNotFoundError:
# Skip if the user doesn't have vpython from depot_tools. # Skip if the user doesn't have vpython from depot_tools.
@ -76,20 +79,25 @@ def run_black():
return subprocess.run( return subprocess.run(
[sys.executable, "-m", "black", "--check", ROOT_DIR] + extra_programs, [sys.executable, "-m", "black", "--check", ROOT_DIR] + extra_programs,
check=False, check=False,
cwd=ROOT_DIR,
).returncode ).returncode
def run_flake8(): def run_flake8():
"""Returns the exit code from flake8.""" """Returns the exit code from flake8."""
return subprocess.run( return subprocess.run(
[sys.executable, "-m", "flake8", ROOT_DIR], check=False [sys.executable, "-m", "flake8", ROOT_DIR],
check=False,
cwd=ROOT_DIR,
).returncode ).returncode
def run_isort(): def run_isort():
"""Returns the exit code from isort.""" """Returns the exit code from isort."""
return subprocess.run( 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 ).returncode