Skip to content

Commit 9fee9cd

Browse files
test(compare): pin plan_valid and update_pending in the run_all() tests
run_all() now ends with plan_valid = saved and not update_pending. The shared fixture starts with update_pending True and several earlier tests leave plan_valid True, so test_run_all_restores_state failed or passed depending on run order. Set a valid plan with no re-plan pending before it, and save and restore both flags in it and in test_run_all_restores_when_config_restore_raises, which left plan_valid False for every later test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 53fa6bd commit 9fee9cd

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎apps/predbat/tests/test_compare.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ def test_run_all_restores_state(my_predbat):
9797
switched plans whatever metric_min_improvement_plan said (seen live on 9 Oct 2026: 300.97p against 30.71p).
9898
"""
9999
names = COMPARE_RESTORED_STATE + COMPARE_RESTORED_COPIES
100+
saved_plan_valid, saved_pending = my_predbat.plan_valid, my_predbat.update_pending
101+
# A valid plan with no re-plan pending, so plan_valid must come back True whatever earlier tests left behind
102+
my_predbat.plan_valid, my_predbat.update_pending = True, False
100103
original = {name: getattr(my_predbat, name) for name in names}
101104
saved_compare_list = my_predbat.args.get("compare_list")
102105
my_predbat.args["compare_list"] = [{"id": "tariff_a", "name": "Tariff A"}, {"id": "tariff_b", "name": "Tariff B"}]
@@ -134,6 +137,7 @@ def run_single(*args, **kwargs):
134137
finally:
135138
for name, value in original.items():
136139
setattr(my_predbat, name, value)
140+
my_predbat.plan_valid, my_predbat.update_pending = saved_plan_valid, saved_pending
137141
if saved_compare_list is None:
138142
my_predbat.args.pop("compare_list", None)
139143
else:
@@ -210,6 +214,7 @@ def test_run_all_restores_when_config_restore_raises(my_predbat):
210214
item = my_predbat.config_index.get("metric_battery_cycle")
211215
saved_compare_list = my_predbat.args.get("compare_list")
212216
saved_preclip, saved_value = my_predbat.plan_preclip, item["value"]
217+
saved_plan_valid, saved_pending = my_predbat.plan_valid, my_predbat.update_pending
213218
plan_in_force = ([18.08], [{"start": 0, "end": 90, "average": 7.62}], [], [])
214219
my_predbat.plan_preclip = plan_in_force
215220
my_predbat.args["compare_list"] = [{"id": "tariff_a", "name": "Tariff A", "config": {"metric_battery_cycle": 9.0}}]
@@ -245,6 +250,7 @@ def fetch_config_options():
245250
finally:
246251
del my_predbat.fetch_config_options
247252
my_predbat.plan_preclip = saved_preclip
253+
my_predbat.plan_valid, my_predbat.update_pending = saved_plan_valid, saved_pending
248254
item["value"] = saved_value
249255
if saved_compare_list is None:
250256
my_predbat.args.pop("compare_list", None)

0 commit comments

Comments
 (0)