From 3518a9a19a5f3640e4fec66445ee16f6aa0e9a04 Mon Sep 17 00:00:00 2001 From: azhengzz <820108271@qq.com> Date: Mon, 27 Sep 2021 23:52:20 +0800 Subject: [PATCH] =?UTF-8?q?bug=20fix:=20=E4=BF=AE=E5=A4=8D=E7=94=B1?= =?UTF-8?q?=E4=BA=8E=E8=AF=AD=E6=B3=95=E9=94=99=E8=AF=AF=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E9=A2=84=E5=A4=84=E7=90=86=E8=84=9A=E6=9C=AC=E6=88=96=E5=90=8E?= =?UTF-8?q?=E5=A4=84=E7=90=86=E8=84=9A=E6=9C=AC=E6=89=A7=E8=A1=8C=E6=8A=A5?= =?UTF-8?q?=E9=94=99=EF=BC=8C=E8=80=8C=E6=8A=A5=E9=94=99=E7=9A=84=E8=A1=8C?= =?UTF-8?q?=E5=8F=B7=E6=98=AF=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/cores/case/base/script.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ApiAutomationTest/app/cores/case/base/script.py b/ApiAutomationTest/app/cores/case/base/script.py index 1e3bd59..37681c3 100644 --- a/ApiAutomationTest/app/cores/case/base/script.py +++ b/ApiAutomationTest/app/cores/case/base/script.py @@ -29,20 +29,26 @@ def exec_script(source, project_id, log, script_type, glb=None, loc=None): loc = {} loc['vars'] = vars loc['log'] = log + loc['__name__'] = '__main__' try: exec(source, glb, loc) except Exception as e: - tb = sys.exc_info()[-1] - script_tb = tb.tb_next + if isinstance(e, SyntaxError): + lineno = e.lineno + else: + tb = sys.exc_info()[-1] + while tb.tb_next: + tb = tb.tb_next + lineno = tb.tb_lineno if script_type == 'PREPROCESSOR_SCRIPT': - failure_message = '预处理脚本执行异常: m行号: %s, 错误信息: %s, 错误类型: %s' % (script_tb.tb_lineno, e.args[0], type(e)) - script_exception = PreScriptExecException(script_tb.tb_lineno, e.args[0], failure_message) + failure_message = '预处理脚本执行异常: m行号: %s, 错误信息: %s, 错误类型: %s' % (lineno, e.args[0], type(e)) + script_exception = PreScriptExecException(lineno, e.args[0], failure_message) log.error('预处理脚本执行异常: 行号: %s, 错误信息: %s' % (script_exception.line_no, script_exception.value)) raise script_exception elif script_type == 'POSTPROCESSOR_SCRIPT': loc['failure'] = True # 后处理脚本异常时,将断言结果置为失败 - failure_message = '后处理脚本执行异常: 行号: %s, 错误信息: %s, 错误类型: %s' % (script_tb.tb_lineno, e.args[0], type(e)) - script_exception = PostScriptExecException(script_tb.tb_lineno, e.args[0], failure_message) + failure_message = '后处理脚本执行异常: 行号: %s, 错误信息: %s, 错误类型: %s' % (lineno, e.args[0], type(e)) + script_exception = PostScriptExecException(lineno, e.args[0], failure_message) loc['failure_message'] = failure_message log.error(failure_message) raise script_exception