def _format_traceback_line(self, tb):
"""
Formats the file / lineno / function line of a traceback element.
Returns None is the line is not relevent to the user i.e. inside the test runner.
"""
if self._is_relevant_tb_level(tb):
return None
f = tb.tb_frame
filename = f.f_code.co_filename
lineno = tb.tb_lineno
linecache.checkcache(filename)
function_name = f.f_code.co_name
line_contents = linecache.getline(filename, lineno, f.f_globals).strip()
return " %s line %s in %s\n %s" % (
termstyle.blue(self._relative_path(filename) if self.use_relative_path else filename),
termstyle.bold(termstyle.cyan(lineno)),
termstyle.cyan(function_name),
line_contents
)
评论列表
文章目录