pytest.ini
[pytest]
addopts = -p no:warnings --log-cli-level=INFO
render_collapsed = failed,error
norecursedirs = case/1 && case/2
log_file = pytest.log
log_file_level = INFO
log_file_format = %(asctime)s | %(filename)s | %(funcName)s | line:%(lineno)d | %(levelname)s | %(message)s
log_file_date_format = %Y-%m-%d %H:%M:%S
addopts = --log-cli-level=INFO
设置了控制台日志的级别为 INFO。log_file = pytest.log
指定了日志文件的名称为 pytest.log
。log_file_level = INFO
设置了日志文件的日志级别为 INFO。log_file_format = %(asctime)s %(levelname)s %(message)s
设置了日志文件的格式,包括时间戳、日志级别和日志消息。log_file_date_format = %Y-%m-%d %H:%M:%S
设置了日志文件中时间戳的格式。import pytest
import logging as log
def test_001(login_session):
log.info('这是一个信息级别的日志')
def test_002():
log.warning('这是一个警告级别的日志')
def test_003():
log.error('这是一个error级别的日志')
def test_004():
log.critical('这是一个critical级别的日志')
@pytest.mark.skip(reason="这个case不执行")
def test_006():
assert 1 == 2
if __name__ == '__main__':
pytest.main(['-s', '-v', 'test_case22.py'])
skip 的case 也可以展示在测试报告中