本文整理汇总了Python中lib.reporting.logger.Logger.failure方法的典型用法代码示例。如果您正苦于以下问题:Python Logger.failure方法的具体用法?Python Logger.failure怎么用?Python Logger.failure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.reporting.logger.Logger
的用法示例。
在下文中一共展示了Logger.failure方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_python_file
# 需要导入模块: from lib.reporting.logger import Logger [as 别名]
# 或者: from lib.reporting.logger.Logger import failure [as 别名]
def run_python_file(args):
"""Run a python file as if it were the main program on the command line.
`args` is the argument array to present as sys.argv, including the first
element representing the file being executed.
Lifted straight from coverage.py by Ned Batchelder
"""
try:
# In Py 2.x, the builtins were in __builtin__
BUILTINS = sys.modules['__builtin__']
except KeyError: # pragma: no cover - not worried about Python 3 yet...
# In Py 3.x, they're in builtins
BUILTINS = sys.modules['builtins']
filename = args[0]
# Create a module to serve as __main__
old_main_mod = sys.modules['__main__']
main_mod = imp.new_module('__main__')
sys.modules['__main__'] = main_mod
main_mod.__file__ = filename
main_mod.__builtins__ = BUILTINS
# Set sys.argv and the first path element properly.
old_argv = sys.argv
old_path0 = sys.path[0]
sys.argv = args
sys.path[0] = os.path.dirname(filename)
try:
sys.stdout = open('outfile.txt', 'w')
source = open(filename, 'rU').read()
exec compile(source, filename, "exec") in main_mod.__dict__
except Exception, ex:
Logger.add_error("%s" % ex)
Logger.failure("Exception in application")