test-backend: Fix testing via shortcuts outside zerver/.

This commit is contained in:
Tim Abbott 2023-11-02 10:25:11 -07:00
parent c56bd24715
commit ac1f1e224b
1 changed files with 23 additions and 21 deletions

View File

@ -283,7 +283,7 @@ def main() -> None:
if options.processes is not None and options.processes < 1: if options.processes is not None and options.processes < 1:
raise argparse.ArgumentTypeError("option processes: Only positive integers are allowed.") raise argparse.ArgumentTypeError("option processes: Only positive integers are allowed.")
zerver_test_dir = "zerver/tests/" test_dirs = ["zerver/tests/", "corporate/tests", "analytics/tests"]
# While running --rerun, we read var/last_test_failure.json to get # While running --rerun, we read var/last_test_failure.json to get
# the list of tests that failed on the last run, and then pretend # the list of tests that failed on the last run, and then pretend
@ -305,7 +305,8 @@ def main() -> None:
args[i] = suite.rstrip("/").replace("/", ".") args[i] = suite.rstrip("/").replace("/", ".")
def rewrite_arguments(search_key: str) -> None: def rewrite_arguments(search_key: str) -> None:
for root, dirs, files_names in os.walk(zerver_test_dir, topdown=False): for test_dir in test_dirs:
for root, dirs, files_names in os.walk(test_dir, topdown=False):
for file_name in files_names: for file_name in files_names:
# Check for files starting with alphanumeric characters and ending with '.py' # Check for files starting with alphanumeric characters and ending with '.py'
# Ignore backup files if any # Ignore backup files if any
@ -329,7 +330,8 @@ def main() -> None:
for i, suite in enumerate(args): for i, suite in enumerate(args):
if suite.startswith("test"): if suite.startswith("test"):
for root, dirs, files_names in os.walk(zerver_test_dir): for test_dir in test_dirs:
for root, dirs, files_names in os.walk(test_dir):
for file_name in files_names: for file_name in files_names:
if file_name in (suite, f"{suite}.py"): if file_name in (suite, f"{suite}.py"):
new_suite = os.path.join(root, file_name) new_suite = os.path.join(root, file_name)