处理 pytest 失败断言的最佳实践
我使用 pyspark、EMR、terraform 和气流进行触发。我正在我的 pyspark 代码中编写 pytest 用例。我有以下问题:
I)如果我得到“False”断言。我正在考虑发送松弛和电子邮件通知并关闭 EMR 集群。这是每个人都遵循的最佳实践吗? 。
有人可以解释如何在断言失败的情况下处理 pytests 吗?或处理 pytest 失败的一般方法
示例代码:
def task_fail_slack_alert(context):
SLACK_CONN_ID = 'slack'
slack_webhook_token = BaseHook.get_connection(SLACK_CONN_ID).password
slack_msg = """
:red_circle: crunchbase Job Failed.
*Task*: {task}
*Dag*: {dag}
*Execution Time*: {exec_date}
*Log Url*: {log_url}
*Error*:{exception}
""".format(
task=context.get('task_instance').task_id,
dag=context.get('task_instance').dag_id,
exec_date=context.get('execution_date'),
log_url=context.get('task_instance').log_url,
exception=context.get('exception')
)
failed_alert = SlackWebhookOperator(
task_id='slack',
http_conn_id='slack',
webhook_token=slack_webhook_token,
message=slack_msg,
username='airflow_sld',
dag=dag)
return failed_alert.execute(context=context)
I am using pyspark, EMR, terraform and airflow for triggering. I am writing pytest cases in my pyspark code. I have the following questions:
I)If I get an assertion as "False". I am thinking of sending a slack and email notification and shut down EMR cluster. is this the best practice that everyone follows? .
Can someone explain how to handle pytests in cases of failure assertions? or general methods of handling pytest failures
Sample code:
def task_fail_slack_alert(context):
SLACK_CONN_ID = 'slack'
slack_webhook_token = BaseHook.get_connection(SLACK_CONN_ID).password
slack_msg = """
:red_circle: crunchbase Job Failed.
*Task*: {task}
*Dag*: {dag}
*Execution Time*: {exec_date}
*Log Url*: {log_url}
*Error*:{exception}
""".format(
task=context.get('task_instance').task_id,
dag=context.get('task_instance').dag_id,
exec_date=context.get('execution_date'),
log_url=context.get('task_instance').log_url,
exception=context.get('exception')
)
failed_alert = SlackWebhookOperator(
task_id='slack',
http_conn_id='slack',
webhook_token=slack_webhook_token,
message=slack_msg,
username='airflow_sld',
dag=dag)
return failed_alert.execute(context=context)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论