Make run_test.py and create_test.py importable without errors (#6736)

Allowing scripts to be importable is good practice in general and it's
required for the pytest testing framework that I'm adding in a follow up
PR.
pull/6726/head
Jelte Fennema 2023-02-27 22:34:42 +01:00 committed by GitHub
parent c018e29bec
commit 17ad61678f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 182 additions and 181 deletions

View File

@ -4,6 +4,7 @@ import os
import random import random
import sys import sys
if __name__ == "__main__":
if len(sys.argv) != 2: if len(sys.argv) != 2:
print( print(
"ERROR: Expected the name of the new test as an argument, such as:\n" "ERROR: Expected the name of the new test as an argument, such as:\n"
@ -34,7 +35,6 @@ SET client_min_messages TO WARNING;
DROP SCHEMA {test_name} CASCADE; DROP SCHEMA {test_name} CASCADE;
""" """
with open(filename, "w") as f: with open(filename, "w") as f:
f.write(contents) f.write(contents)

View File

@ -15,6 +15,7 @@ import common
import config import config
if __name__ == "__main__":
args = argparse.ArgumentParser() args = argparse.ArgumentParser()
args.add_argument( args.add_argument(
"test_name", help="Test name (must be included in a schedule.)", nargs="?" "test_name", help="Test name (must be included in a schedule.)", nargs="?"
@ -26,7 +27,9 @@ args.add_argument(
help="Relative path for test file (must have a .sql or .spec extension)", help="Relative path for test file (must have a .sql or .spec extension)",
type=pathlib.Path, type=pathlib.Path,
) )
args.add_argument("-r", "--repeat", help="Number of test to run", type=int, default=1) args.add_argument(
"-r", "--repeat", help="Number of test to run", type=int, default=1
)
args.add_argument( args.add_argument(
"-b", "-b",
"--use-base-schedule", "--use-base-schedule",
@ -56,7 +59,6 @@ test_file_name = args["test_name"]
use_base_schedule = args["use_base_schedule"] use_base_schedule = args["use_base_schedule"]
use_whole_schedule_line = args["use_whole_schedule_line"] use_whole_schedule_line = args["use_whole_schedule_line"]
class TestDeps: class TestDeps:
schedule: Optional[str] schedule: Optional[str]
direct_extra_tests: list[str] direct_extra_tests: list[str]
@ -76,7 +78,6 @@ class TestDeps:
return list(all_deps.keys()) return list(all_deps.keys())
deps = { deps = {
"multi_cluster_management": TestDeps( "multi_cluster_management": TestDeps(
None, ["multi_test_helpers_superuser"], repeatable=False None, ["multi_test_helpers_superuser"], repeatable=False
@ -92,7 +93,6 @@ if not (test_file_name or test_file_path):
print("FATAL: No test given.") print("FATAL: No test given.")
sys.exit(2) sys.exit(2)
if test_file_path: if test_file_path:
test_file_path = os.path.join(os.getcwd(), args["path"]) test_file_path = os.path.join(os.getcwd(), args["path"])
@ -128,7 +128,6 @@ for schedule_file_path in sorted(glob(os.path.join(regress_dir, "*_schedule"))):
else: else:
raise Exception("Test could not be found in any schedule") raise Exception("Test could not be found in any schedule")
def default_base_schedule(test_schedule): def default_base_schedule(test_schedule):
if "isolation" in test_schedule: if "isolation" in test_schedule:
return "base_isolation_schedule" return "base_isolation_schedule"
@ -151,14 +150,15 @@ def default_base_schedule(test_schedule):
return "minimal_schedule" return "minimal_schedule"
if test_schedule in config.ARBITRARY_SCHEDULE_NAMES: if test_schedule in config.ARBITRARY_SCHEDULE_NAMES:
print(f"WARNING: Arbitrary config schedule ({test_schedule}) is not supported.") print(
f"WARNING: Arbitrary config schedule ({test_schedule}) is not supported."
)
sys.exit(0) sys.exit(0)
if use_base_schedule: if use_base_schedule:
return "base_schedule" return "base_schedule"
return "minimal_schedule" return "minimal_schedule"
if test_file_name in deps: if test_file_name in deps:
dependencies = deps[test_file_name] dependencies = deps[test_file_name]
else: else:
@ -172,7 +172,9 @@ tmp_schedule_path = os.path.join(
# some tests don't need a schedule to run # some tests don't need a schedule to run
# e.g tests that are in the first place in their own schedule # e.g tests that are in the first place in their own schedule
if dependencies.schedule: if dependencies.schedule:
shutil.copy2(os.path.join(regress_dir, dependencies.schedule), tmp_schedule_path) shutil.copy2(
os.path.join(regress_dir, dependencies.schedule), tmp_schedule_path
)
with open(tmp_schedule_path, "a") as myfile: with open(tmp_schedule_path, "a") as myfile:
for dependency in dependencies.extra_tests(): for dependency in dependencies.extra_tests():
myfile.write(f"test: {dependency}\n") myfile.write(f"test: {dependency}\n")
@ -184,7 +186,6 @@ with open(tmp_schedule_path, "a") as myfile:
for _ in range(repetition_cnt): for _ in range(repetition_cnt):
myfile.write(test_schedule_line) myfile.write(test_schedule_line)
# find suitable make recipe # find suitable make recipe
if dependencies.schedule == "base_isolation_schedule": if dependencies.schedule == "base_isolation_schedule":
make_recipe = "check-isolation-custom-schedule" make_recipe = "check-isolation-custom-schedule"