This is an automated email from the ASF dual-hosted git repository.
eladkal pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new c404434737f Fix tests in test_dag to account for month change (#48607)
c404434737f is described below
commit c404434737f1df992ec6b4ddc5a0d8fafb6b3b31
Author: Amogh Desai <[email protected]>
AuthorDate: Tue Apr 1 13:39:14 2025 +0530
Fix tests in test_dag to account for month change (#48607)
* Fix tests in test_dag to account for month change
---
airflow-core/tests/unit/models/test_dag.py | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/airflow-core/tests/unit/models/test_dag.py
b/airflow-core/tests/unit/models/test_dag.py
index 602a899a064..b2af9adcb89 100644
--- a/airflow-core/tests/unit/models/test_dag.py
+++ b/airflow-core/tests/unit/models/test_dag.py
@@ -846,9 +846,9 @@ class TestDag:
# Instead of comparing exact dates, verify it's relatively recent
and not the old start date
current_time = timezone.utcnow()
- # Verify it's not using the old DEFAULT_DATE from 2016
- assert model.next_dagrun.year == current_time.year
- assert model.next_dagrun.month == current_time.month
+ # Verify it's not using the old DEFAULT_DATE from 2016 and is
after that since we are picking up present date.
+ assert model.next_dagrun.year >= DEFAULT_DATE.year
+ assert model.next_dagrun.month >= DEFAULT_DATE.month
# Verify the date is within a reasonable range of the current date
# (allowing for timezone differences and scheduling details)
@@ -1988,10 +1988,10 @@ my_postgres_conn:
assert next_info.logical_date == timezone.datetime(2016, 1, 1, 10, 10)
# Test catchup=False scenario (using current dates)
- current_time = timezone.utcnow()
+ start_date = timezone.datetime(2016, 1, 1, 10, 10, 0)
dag = DAG(
dag_id="test_scheduler_auto_align_3",
- start_date=timezone.datetime(2016, 1, 1, 10, 10, 0),
+ start_date=start_date,
schedule="4 5 * * *",
catchup=False,
)
@@ -2001,15 +2001,17 @@ my_postgres_conn:
assert next_info
# With catchup=False, next_dagrun should be based on the current date
# Verify it's not using the old start_date
- assert next_info.logical_date.year == current_time.year
- assert next_info.logical_date.month == current_time.month
+ assert next_info.logical_date.year >= start_date.year
+ assert next_info.logical_date.month >= start_date.month
+
# Verify it's following the cron schedule pattern (4 5 * * *)
assert next_info.logical_date.hour == 5
assert next_info.logical_date.minute == 4
+ start_date = timezone.datetime(2016, 1, 1, 10, 10, 0)
dag = DAG(
dag_id="test_scheduler_auto_align_4",
- start_date=timezone.datetime(2016, 1, 1, 10, 10, 0),
+ start_date=start_date,
schedule="10 10 * * *",
catchup=False,
)
@@ -2019,8 +2021,8 @@ my_postgres_conn:
assert next_info
# With catchup=False, next_dagrun should be based on the current date
# Verify it's not using the old start_date
- assert next_info.logical_date.year == current_time.year
- assert next_info.logical_date.month == current_time.month
+ assert next_info.logical_date.year >= start_date.year
+ assert next_info.logical_date.month >= start_date.month
# Verify it's following the cron schedule pattern (10 10 * * *)
assert next_info.logical_date.hour == 10
assert next_info.logical_date.minute == 10