mirror of https://github.com/citusdata/citus.git
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
parent
c018e29bec
commit
17ad61678f
|
@ -4,6 +4,7 @@ import os
|
|||
import random
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
print(
|
||||
"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;
|
||||
"""
|
||||
|
||||
|
||||
with open(filename, "w") as f:
|
||||
f.write(contents)
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import common
|
|||
|
||||
import config
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = argparse.ArgumentParser()
|
||||
args.add_argument(
|
||||
"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)",
|
||||
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(
|
||||
"-b",
|
||||
"--use-base-schedule",
|
||||
|
@ -56,7 +59,6 @@ test_file_name = args["test_name"]
|
|||
use_base_schedule = args["use_base_schedule"]
|
||||
use_whole_schedule_line = args["use_whole_schedule_line"]
|
||||
|
||||
|
||||
class TestDeps:
|
||||
schedule: Optional[str]
|
||||
direct_extra_tests: list[str]
|
||||
|
@ -76,7 +78,6 @@ class TestDeps:
|
|||
|
||||
return list(all_deps.keys())
|
||||
|
||||
|
||||
deps = {
|
||||
"multi_cluster_management": TestDeps(
|
||||
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.")
|
||||
sys.exit(2)
|
||||
|
||||
|
||||
if test_file_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:
|
||||
raise Exception("Test could not be found in any schedule")
|
||||
|
||||
|
||||
def default_base_schedule(test_schedule):
|
||||
if "isolation" in test_schedule:
|
||||
return "base_isolation_schedule"
|
||||
|
@ -151,14 +150,15 @@ def default_base_schedule(test_schedule):
|
|||
return "minimal_schedule"
|
||||
|
||||
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)
|
||||
|
||||
if use_base_schedule:
|
||||
return "base_schedule"
|
||||
return "minimal_schedule"
|
||||
|
||||
|
||||
if test_file_name in deps:
|
||||
dependencies = deps[test_file_name]
|
||||
else:
|
||||
|
@ -172,7 +172,9 @@ tmp_schedule_path = os.path.join(
|
|||
# some tests don't need a schedule to run
|
||||
# e.g tests that are in the first place in their own 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:
|
||||
for dependency in dependencies.extra_tests():
|
||||
myfile.write(f"test: {dependency}\n")
|
||||
|
@ -184,7 +186,6 @@ with open(tmp_schedule_path, "a") as myfile:
|
|||
for _ in range(repetition_cnt):
|
||||
myfile.write(test_schedule_line)
|
||||
|
||||
|
||||
# find suitable make recipe
|
||||
if dependencies.schedule == "base_isolation_schedule":
|
||||
make_recipe = "check-isolation-custom-schedule"
|
||||
|
|
Loading…
Reference in New Issue