Skip to content

Commit 5028c3f

Browse files
added a way to skip individual tests for a run
1 parent e71a14f commit 5028c3f

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

l10n_CM/run_l10n.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def run_tests(reg, site, flg, all_tests):
8989
flg (list[str]): The list of pytest flags to be used.
9090
all_tests (list[str]): The list of test file paths to execute.
9191
"""
92+
all_tests = remove_skipped_tests(all_tests, site, reg)
9293
try:
9394
if len(all_tests) > 0:
9495
logging.info(f"Tests for {reg} region on {site} page.")
@@ -128,6 +129,56 @@ def get_region_tests(test_region: str) -> list[str]:
128129
)
129130

130131

132+
def remove_skipped_tests(extracted_tests, live_site, reg):
133+
"""
134+
Reads the mapping for the given region and site and removes any tests that are marked as skipped.
135+
136+
Args:
137+
extracted_tests (list[str]): The list of test file paths to execute.
138+
live_site (str): Page being tested.
139+
reg (str): The test region identifier.
140+
Returns:
141+
list[str]: A list of test file paths for the given region.
142+
"""
143+
mid_path = f"/{reg}/" if live_site != "demo" else "/"
144+
live_sites = [
145+
(f"{live_site}{mid_path}{live_site}_{suffix}", f"_{suffix}_")
146+
for suffix in ("ad", "cc")
147+
]
148+
for live_site, suffix in live_sites:
149+
skipped_tests = get_skipped_tests(live_site)
150+
if skipped_tests and skipped_tests != "All":
151+
skipped_tests = list(
152+
map(
153+
lambda test: os.path.join(current_dir, "Unified", test),
154+
skipped_tests,
155+
)
156+
)
157+
should_keep_test = (
158+
lambda test: suffix in test
159+
if skipped_tests == "All"
160+
else test not in skipped_tests
161+
)
162+
extracted_tests = list(filter(should_keep_test, extracted_tests))
163+
return list(extracted_tests)
164+
165+
166+
def get_skipped_tests(live_site) -> list[str] | str:
167+
"""
168+
Read the mapping for the given region and site and return any tests that are marked as skipped.
169+
170+
Arg:
171+
live_site (str): The site is being tested.
172+
Returns:
173+
list[str] | str: A list of tests that should be skipped, or "All" if all tests should be skipped.
174+
"""
175+
with open(current_dir + "/constants/" + live_site + ".json", "r") as fp:
176+
live_site_data = load(fp)
177+
if live_site_data.get("skip"):
178+
return "All"
179+
return live_site_data.get("skipped", [])
180+
181+
131182
def get_flags_and_sanitize(flags_arguments: list[str]) -> list[str]:
132183
"""
133184
Extract and validate pytest flags from command-line arguments.

0 commit comments

Comments
 (0)