Skip to content

Commit e059169

Browse files
author
Alan Christie
committed
feat: Grouped tests now use _run_a_test
1 parent 99fedd1 commit e059169

File tree

1 file changed

+60
-20
lines changed

1 file changed

+60
-20
lines changed

src/jote/jote.py

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353

5454
class TestResult(Enum):
55-
"""Return value from '_run_a-test()'"""
55+
"""Return value from '_run_a_test()'"""
5656

5757
FAILED = 0
5858
PASSED = 1
@@ -149,6 +149,7 @@ def _check_cwd() -> bool:
149149

150150
def _add_grouped_test(
151151
jd_filename: str,
152+
job_collection: str,
152153
job_name: str,
153154
job: List[DefaultMunch],
154155
run_group_names: List[str],
@@ -178,7 +179,7 @@ def _add_grouped_test(
178179
{
179180
"test-group-name": run_group_name,
180181
"test-group": test_group_definition,
181-
"jobs": [(job_name, job)],
182+
"jobs": [(job_collection, job_name, job)],
182183
}
183184
]
184185
else:
@@ -190,7 +191,9 @@ def _add_grouped_test(
190191
# the group name, the group definition and the list of jobs.
191192
if existing_file_run_groups["test-group-name"] == run_group_name:
192193
# Another job for an existing test group
193-
existing_file_run_groups["jobs"].append((job_name, job))
194+
existing_file_run_groups["jobs"].append(
195+
(job_collection, job_name, job)
196+
)
194197
found_test_group = True
195198
# Did we find an existing test group?
196199
if not found_test_group:
@@ -199,7 +202,7 @@ def _add_grouped_test(
199202
{
200203
"test-group-name": run_group_name,
201204
"test-group": test_group_definition,
202-
"jobs": [(job_name, job)],
205+
"jobs": [(job_collection, job_name, job)],
203206
}
204207
)
205208

@@ -271,6 +274,8 @@ def _load(
271274
if job_def:
272275
jd_munch: DefaultMunch = DefaultMunch.fromDict(job_def)
273276

277+
jd_collection: str = jd_munch["collection"]
278+
274279
# Test groups defined in this file...
275280
test_groups: List[DefaultMunch] = []
276281
if "test-groups" in jd_munch:
@@ -314,6 +319,7 @@ def _load(
314319
if test_run_group_names:
315320
_add_grouped_test(
316321
jd_path,
322+
jd_collection,
317323
jd_name,
318324
jd_munch.jobs[jd_name],
319325
test_run_group_names,
@@ -854,6 +860,7 @@ def _run_grouped_tests(
854860
#
855861
# See '_add_grouped_test()', which is used by _load() to build the map.
856862

863+
test_result: Optional[TestResult] = None
857864
for jd_filename, grouped_tests in grouped_job_definitions.items():
858865

859866
# The grouped definitions are indexed by JobDefinition filename
@@ -866,27 +873,29 @@ def _run_grouped_tests(
866873
# and this isn't it, so skip these tests.
867874
continue
868875
group_struct: Dict[str, Any] = file_run_group["test-group"]
869-
jobs: List[Tuple[str, DefaultMunch]] = file_run_group["jobs"]
876+
jobs: List[Tuple[str, str, DefaultMunch]] = file_run_group["jobs"]
870877

871878
# We have a run-group structure (e.g. a name and optional compose file)
872879
# and a list of jobs (job definitions), each with at least one test in
873880
# the group.
874881
# We need to collect: -
875882
# 0 - the name of the run-group,
876883
# 1 - the test ordinal
877-
# 2 - the job name
878-
# 3 - the job test name
879-
# 4 - the job definition
884+
# 2 - the job collection
885+
# 3 - the job name
886+
# 4 - the job test name
887+
# 5 - the job definition
880888
# We'll sort after we've collected every test for this group.
881889
#
882890
# The job is a DefaultMunch and contains everything for that
883891
# job, including its tests.
884892
grouped_tests = []
885893
for job in jobs:
894+
# the 'job' is a tuple of collection, job name and DefaultMunch.
886895
# The Job will have a tests section.
887-
for job_test_name in job[1].tests:
888-
if "run-groups" in job[1].tests[job_test_name]:
889-
for run_group in job[1].tests[job_test_name]["run-groups"]:
896+
for job_test_name in job[2].tests:
897+
if "run-groups" in job[2].tests[job_test_name]:
898+
for run_group in job[2].tests[job_test_name]["run-groups"]:
890899
if run_group.name == run_group_name:
891900
# OK - we have a test for this group.
892901
# Its ordinal must be unique!
@@ -911,9 +920,10 @@ def _run_grouped_tests(
911920
(
912921
group_struct,
913922
run_group.ordinal,
914-
job[0],
923+
job[0], # Collection
924+
job[1], # Job (name)
915925
job_test_name,
916-
job[1],
926+
job[2], # Job definition
917927
)
918928
)
919929

@@ -925,7 +935,7 @@ def _run_grouped_tests(
925935
# 1. Apply the group compose file (if there is one)
926936
# 2. run the tests (in ordinal order)
927937
# 3. stop the compose file
928-
compose_file: Optional[str] = None
938+
group_compose_file: Optional[str] = None
929939
for index, grouped_test in enumerate(grouped_tests):
930940

931941
# For each grouped test we have a test-group definition,
@@ -940,18 +950,48 @@ def _run_grouped_tests(
940950
)
941951

942952
# The test
943-
print(
944-
f"Grouped Test =-> {jd_filename}/{grouped_test[0].name}[{grouped_test[1]}]:"
945-
f' job="{grouped_test[2]}" test="{grouped_test[3]}"'
953+
compose, test_result = _run_a_test(
954+
args,
955+
jd_filename,
956+
grouped_test[2],
957+
grouped_test[3],
958+
grouped_test[4],
959+
grouped_test[5],
946960
)
947961

948-
# Stop the group compose file?
949-
if compose_file:
962+
# Always try and teardown the test compose
963+
# between tests in a group.
964+
if compose:
965+
compose.delete()
966+
967+
# And stop if any test has failed.
968+
if test_result == TestResult.FAILED:
969+
tests_failed += 1
970+
break
971+
972+
if test_result == TestResult.PASSED:
973+
tests_passed += 1
974+
elif test_result == TestResult.SKIPPED:
975+
tests_skipped += 1
976+
elif test_result == TestResult.IGNORED:
977+
tests_ignored += 1
978+
979+
# Always stop the group compose file at the end of the test group
980+
# (if there is one)
981+
if group_compose_file:
950982
print(
951983
f"Grouped Test =-> {jd_filename}:"
952-
f' compose-file="{compose_file}" [DOWN]'
984+
f' compose-file="{group_compose_file}" [DOWN]'
953985
)
954986

987+
# Told to exit on first failure?
988+
if test_result == TestResult.FAILED and args.exit_on_failure:
989+
break
990+
991+
# Told to exit on first failure?
992+
if test_result == TestResult.FAILED and args.exit_on_failure:
993+
break
994+
955995
return tests_passed, tests_skipped, tests_ignored, tests_failed
956996

957997

0 commit comments

Comments
 (0)