在线客服
扫描二维码
下载博学谷APP扫描二维码
关注博学谷微信公众号
今天我们来梳理一下自动化测试中的Python logging源码学习笔记,主要内容分为三个部分,分别是基本使用、文件存储与日志打印和API。感兴趣的小伙伴赶紧一起来看看吧~
1、基本使用
import logging
# logging 日志配置
logging.basicConfig(filename='exampe.log',level=logging.DEBUG)
logging.debug("helloworld - debug")
logging.info('hello info')
logging.warning('hello warning')
logging.error('hello error')logging.critical('hello critical')
2、文件存储与日志打印
import logging
# create logger
logger = logging.getLogger('simple_example')
logger.setLevel(logging.DEBUG)
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
fl = logging.FileHandler('app.log')
fl.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
# add formatter to ch
ch.setFormatter(formatter)
fl.setFormatter(formatter)
# add ch to logger
logger.addHandler(ch)
logger.addHandler(fl)
# 'application' code
logger.debug('debug message')
logger.info('info message')
logger.warning('warn message')
logger.error('error message')
logger.critical('critical message')
3、API
import requests
import logging
logging.basicConfig(format='%(levelname)s %(asctime)s %(message)s',level=logging.DEBUG)
base_url = "http://39.107.96.138:3000/api/v1/"
testdata = {
"accesstoken":"49b2e830-4305-475d-b6b5-52287
cc5daaa",
"title":"2313131231231232",
"tab":"ask",
"content":"xxxxxxxxxxxxx"
}
def test_new_topic():
"""
测试发布话题
:return:
"""
url = base_url+'topics'
logging.info(f"开始发送Post请求{url},请求数据为{str(testdata)}")
r = requests.post(url,json=testdata)
jsonData = r.json()
logging.info(f'发送请求完成,结果为{str(jsonData)}')
assert r.status_code == 200
assert jsonData['success']
logging.info(f"test_new_topic, topicid: {jsonData['topic_
id']}")
assert jsonData['topic_id'] is not None
return jsonData['topic_id']
以上就是Python logging源码学习笔记的全部内容,如果想学习更多关于自动化测试的知识点,可以在博学谷官网报名申请相关免费课程的试听~
— 申请免费试学名额 —
在职想转行提升,担心学不会?根据个人情况规划学习路线,闯关式自适应学习模式保证学习效果
讲师一对一辅导,在线答疑解惑,指导就业!
相关推荐 更多
软件测试工作中有哪些常用的工具?
软件测试工作中有哪些常用的工具?一般来说软件测试工具有开源测试管理工具、开源功能自动化测试工具、开源性能自动化测试工具、Quality Center、QuickTest Professional、LoadRunner等。
9274
2019-05-15 17:43:21
软件测试学习之测试用例的常用方法盘点
测试用例是为某个特殊目标而编制的一组测试输入、执行条件以及预期结果,以便测试某个程序路径或核实是否满足某个特定需求。本文将盘点测试用例的常见方法,即等价类划分法、边界值法、测试大纲法、场景法、错误推断法、随机测试和需求文档转化法。
6179
2019-08-13 13:22:47
软件测试过程的步骤分析
软件测试过程可以分为5个步骤,即单元测试、集成测试、确认测试、系统测试、验收测试。本文将详细分析这5个步骤的主要内容和意义,和大家谈谈各个步骤的具体操作流程。
7542
2019-08-19 11:46:24
自动化测试的测试模型有哪些?优缺点分别是什么?
自动化测试的测试模型有哪些?测试行业从业者需要掌握的测试模型有线性测试、模块化驱动测试、数据驱动测试以及行为驱动测试 ,这些测试模型的优缺点也十分鲜明。下面我们一起来详细分析一下吧!
5701
2020-07-15 11:47:58
测试怎么选择抓包软件?
作为一名测试,会抓包是必不可少的,比较主流的抓包工具如:Fiddler、Charles、wireshark等,市面上这么多的抓包工具,各有优势和劣势,没必要全都会使用,找到最适合自己的一款抓包软件即可,该怎么选择呢?下面我就帮大家分析分析。
5854
2020-07-17 11:03:21