前言
pytest 框架有日志管理开关,不需要再添加额外的配置
logging的使用
在用例中添加logging的日志内容
import pytest
import logging
log = logging.getLogger(__name__)
@pytest.fixture
def first():
log.debug('debug message: first to do .........')
def inc(x):
log.info('function inc--------')
return x + 1
def test_answer(first):
log.debug('run case: test_answer')
log.info('test case --------')
assert inc(3) == 4
直接运行pytest是不会用日志输出的,因为默认仅输出warning 以上的级别日志
开启日志
要想看到打印日志,先在pytest.ini 配置开启日志,并且设置日志级别
[pytest]
log_cli = true
log_cli_level = info
运行用例
>pytest test_log.py
========&