uranusjr commented on code in PR #29929:
URL: https://github.com/apache/airflow/pull/29929#discussion_r1201407333
##########
tests/executors/test_kubernetes_executor.py:
##########
@@ -1162,6 +1166,39 @@ def test_supports_pickling(self):
def test_supports_sentry(self):
assert not KubernetesExecutor.supports_sentry
+ def test_annotations_for_logging_task_metadata(self):
+ annotations_test = {
+ "dag_id": "dag",
+ "run_id": "run_id",
+ "task_id": "task",
+ "try_number": "1",
+ }
+ with mock.patch.dict(
+ os.environ, {"AIRFLOW__KUBERNETES_EXECUTOR__LOGS_TASK_METADATA":
"True"}, clear=True
+ ):
+ expected_annotations = {
+ "dag_id": "dag",
+ "run_id": "run_id",
+ "task_id": "task",
+ "try_number": "1",
+ }
+ annotations_actual =
annotations_for_logging_task_metadata(annotations_test)
+ assert annotations_actual == expected_annotations
+
+ def test_annotations_for_logging_task_metadata_fallback(self):
+ annotations_test = {
+ "dag_id": "dag",
+ "run_id": "run_id",
+ "task_id": "task",
+ "try_number": "1",
+ }
+ with mock.patch.dict(
+ os.environ, {"AIRFLOW__KUBERNETES_EXECUTOR__LOGS_TASK_METADATA":
"False"}, clear=True
+ ):
+ expected_annotations = "<omitted>"
+ annotations_actual =
annotations_for_logging_task_metadata(annotations_test)
+ assert annotations_actual == expected_annotations
+
Review Comment:
Instead of using `mock.patch`, it’s more reliable to use the `conf_vars`
helper. You also want to patch both the true and false cases because it’s not
deterministic in the CI which the config is set to when the test is run.
--
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]