IT培训选达内,21年专业IT培训机构,美国上市集团。开设IT培训班Java、python、大数据、linux、UI、会计等IT培训,泛IT培训和非IT培训共2课程、室内设计师、PHP工程师、平面++工程师、SEM竞价师、SEO优化师、社会化媒体运营师、电商运营师等课程为一体的IT培训机构。以下5家IT培训培训机构均已经受过学生的考验,不分前后,值得推荐!
1.广州达内教育
2.广州博为峰教育
3.广州中公教育优就业
4.广州CDA数据分析师分院
5.广州北大青鸟
6.广州信盈达
7.广州千锋教育
8.广州传智教育
9.广州黑马程序员
10.广州斯坦星球
今天我们来梳理一下自动化测试中的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源码学习笔记的全部内容,如果想学习更多关于自动化测试的知识点,可以在达内报名申请相关0元课程的试听~