From c5744711cc773bce4f4089c3d81c0fd2ba77121f Mon Sep 17 00:00:00 2001 From: "F.N. Claessen" Date: Tue, 1 Sep 2026 18:56:06 +0200 Subject: [PATCH] cli/tests: freeze the clock in test_run_automations Context: - The test invokes `flexmeasures jobs run-automations` twice and asserts that the second invocation finds nothing due, which only holds while both land in the same clock minute. - The automations it sets up recur every minute, so once a slow first invocation crosses a minute boundary, they are legitimately due again and the assertion fails. Seen on Python 3.11 in CI. Change: - Froze the clock with the existing freeze_server_now fixture, as the neighbouring catch-up test already does, so the test no longer depends on how long its first invocation takes. Signed-off-by: F.N. Claessen --- flexmeasures/cli/tests/test_automations.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/flexmeasures/cli/tests/test_automations.py b/flexmeasures/cli/tests/test_automations.py index 8373b5cf18..14e26569d4 100644 --- a/flexmeasures/cli/tests/test_automations.py +++ b/flexmeasures/cli/tests/test_automations.py @@ -736,7 +736,9 @@ def test_add_automation_rejects_non_object_yaml_file( assert "Traceback" not in result.output -def test_run_automations(app, fresh_db, setup_dummy_data, clean_redis): +def test_run_automations( + app, fresh_db, setup_dummy_data, clean_redis, freeze_server_now +): """Active automations due this minute queue forecasting jobs (with trigger meta data); inactive ones do not. We use two automations with the same forecaster config (thus sharing a generator data source), @@ -745,6 +747,10 @@ def test_run_automations(app, fresh_db, setup_dummy_data, clean_redis): from flexmeasures.cli.data_add import add_automation from flexmeasures.cli.jobs import run_automations + # Freeze the clock, as this test runs the runner twice and asserts that the second + # run finds nothing due. Without freezing, a slow first run can cross a minute + # boundary, after which an every-minute automation is legitimately due again. + freeze_server_now(datetime(2026, 1, 15, 8, 58, 30, tzinfo=timezone.utc)) sensor1_id, sensor2_id = setup_dummy_data[0], setup_dummy_data[1] runner = app.test_cli_runner() for name, sensor_id in [