前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >视频 | Python测试开发之调试print代码实例

视频 | Python测试开发之调试print代码实例

作者头像
苦叶子
修改2018-11-30 13:09:18
4910
修改2018-11-30 13:09:18
举报
文章被收录于专栏:开源优测
视频内容
代码语言:javascript
复制
# -*- coding: utf-8 -*-

__author__ = "苦叶子"

"""

公众号: 开源优测

Email: lymking@foxmail.com

"""

import sys


# 定义print输出级别, 用于控制print输出
# 优先级 DEBUG > INFO > WARNING > ERROR
class Print:
    DEBUG = 0
    INFO = 1
    WARNING = 2
    ERROR = 3
    PRINT_TIP = {DEBUG: "Debug", INFO: "Info", WARNING: "Warn", ERROR: "Error"}


# 全局print控制标志
PRINT_LEVEL = Print.ERROR


# 自定义print输出
# msg - 输出内容
# level - 输出级别控制
def print_console(msg, level=Print.INFO):
    filename = sys._getframe().f_code.co_filename
    func = sys._getframe().f_code.co_name
    line = sys._getframe().f_lineno
    if level >= PRINT_LEVEL:
        print("In File: %s, Function: %s @line: %s  %s: %s" % (filename, func, line, Print.PRINT_TIP[level], msg))


# 测试print_console
def test_print_console():
    print_console("这是debug输出...", Print.DEBUG)

    print_console("这是info输出....", Print.INFO)

    print_console("这是warning输出...", Print.WARNING)

    print_console("这是error输出", Print.ERROR)

    print("---" * 10)


if __name__ == "__main__":
    print("print输出示例")

    # 设置输出为DEBUG级别
    PRINT_LEVEL = Print.DEBUG
    test_print_console()

    # 设置输出为INFO级别
    PRINT_LEVEL = Print.INFO
    test_print_console()

    # 设置输出为Warning级别
    PRINT_LEVEL = Print.WARNING
    test_print_console()

    # 设置输出为ERROR级别
    PRINT_LEVEL = Print.ERROR
    test_print_console()
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2018-10-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 开源优测 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档