Skip to content

Commit 3667de1

Browse files
vapierLUCI
authored and
LUCI
committed
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 <[email protected]> Tested-by: Mike Frysinger <[email protected]> Commit-Queue: Mike Frysinger <[email protected]>
1 parent 85ee173 commit 3667de1

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

run_tests

+13-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import subprocess
2121
import sys
2222
from typing import List
2323

24-
import pytest
25-
2624

2725
ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
2826

@@ -38,7 +36,11 @@ def run_pytest(argv: List[str]) -> int:
3836
if is_ci():
3937
argv = ["-m", "not skip_cq"] + argv
4038

41-
return pytest.main(argv)
39+
return subprocess.run(
40+
[sys.executable, "-m", "pytest"] + argv,
41+
check=False,
42+
cwd=ROOT_DIR,
43+
).returncode
4244

4345

4446
def run_pytest_py38(argv: List[str]) -> int:
@@ -57,6 +59,7 @@ def run_pytest_py38(argv: List[str]) -> int:
5759
]
5860
+ argv,
5961
check=False,
62+
cwd=ROOT_DIR,
6063
).returncode
6164
except FileNotFoundError:
6265
# Skip if the user doesn't have vpython from depot_tools.
@@ -76,20 +79,25 @@ def run_black():
7679
return subprocess.run(
7780
[sys.executable, "-m", "black", "--check", ROOT_DIR] + extra_programs,
7881
check=False,
82+
cwd=ROOT_DIR,
7983
).returncode
8084

8185

8286
def run_flake8():
8387
"""Returns the exit code from flake8."""
8488
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,
8692
).returncode
8793

8894

8995
def run_isort():
9096
"""Returns the exit code from isort."""
9197
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,
93101
).returncode
94102

95103

0 commit comments

Comments
 (0)