You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/12/05 15:28:06 UTC
[GitHub] [airflow] vincbeck commented on a diff in pull request #28052: Fix EmrAddStepsOperature wait_for_completion parameter is not working
vincbeck commented on code in PR #28052:
URL: https://github.com/apache/airflow/pull/28052#discussion_r1039744012
##########
tests/providers/amazon/aws/operators/test_emr_add_steps.py:
##########
@@ -207,3 +207,22 @@ def test_init_with_nonexistent_cluster_name(self):
with pytest.raises(AirflowException) as ctx:
operator.execute(self.mock_context)
assert str(ctx.value) == f"No cluster found for name: {cluster_name}"
+
+ def test_wait_for_completion(self):
+ def check_wait_for_completion(**kwargs):
+ return kwargs.get("wait_for_completion")
+
+ wait_for_completion = False
+ with patch(
+ "airflow.providers.amazon.aws.hooks.emr.EmrHook.add_job_flow_steps"
+ ) as mock_add_job_flow_steps:
+ mock_add_job_flow_steps.side_effect = check_wait_for_completion
+ operator = EmrAddStepsOperator(
+ task_id="test_task",
+ job_flow_id="j-8989898989",
+ aws_conn_id="aws_default",
+ dag=DAG("test_dag_id", default_args=self.args),
+ wait_for_completion=wait_for_completion,
+ )
+
+ assert operator.execute(self.mock_context) == wait_for_completion
Review Comment:
I m not sure about your unit test, I hardly understand the logic. Here is how I'd write it:
```suggestion
@mock.patch.object(EmrHook, "add_job_flow_steps")
def test_wait_for_completion(self, mock_add_job_flow_steps):
job_flow_id = "j-8989898989"
operator = EmrAddStepsOperator(
task_id="test_task",
job_flow_id=job_flow_id,
aws_conn_id="aws_default",
dag=DAG("test_dag_id", default_args=self.args),
wait_for_completion=False,
)
mock_add_job_flow_steps.assert_called_once_with(
job_flow_id=job_flow_id,
steps=[],
wait_for_completion=False,
)
```
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org