uranusjr commented on code in PR #33645:
URL: https://github.com/apache/airflow/pull/33645#discussion_r1304031108
##########
tests/models/test_taskinstance.py:
##########
@@ -2890,6 +2890,33 @@ def test_echo_env_variables(self, dag_maker):
ti.refresh_from_db()
assert ti.state == State.SUCCESS
+ def test_context_inside_template(self, dag_maker):
+ def user_defined_macro():
+ from airflow.operators.python import get_current_context
+
+ get_current_context()
+
+ with dag_maker(
+ "test_context_inside_template",
+ start_date=DEFAULT_DATE,
+ end_date=DEFAULT_DATE + datetime.timedelta(days=10),
+ user_defined_macros={"user_defined_macro": user_defined_macro},
+ ):
+
+ def foo(arg):
+ print(arg)
+
+ PythonOperator(
+ task_id="context_inside_template",
+ python_callable=foo,
+ op_kwargs={"arg": "{{ user_defined_macro() }}"},
+ ),
+ dagrun = dag_maker.create_dagrun()
+ tis = dagrun.get_task_instances()
+ ti: TaskInstance = next(x for x in tis if x.task_id ==
"context_inside_template")
+ ti._run_raw_task()
+ assert ti.state == State.SUCCESS
Review Comment:
Do we need to actually run the task, or can we only test the rendering part?
Less moving parts if possible.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]