【发布时间】:2020-06-11 16:22:56
【问题描述】:
当生成报告时,如何在显示详细信息链接的捕获日志中删除看起来是 ASCII 的内容?从命令行运行时,ASCII 似乎出现了,但不使用 PyCharm(addopts = --html=./logs/report.html --self-contained-html)。 图片: Report showing ASCII
另外,您如何摆脱testscript 名称和行号?这在命令行以及 PyCharm 中运行时会出现。
图片:
Report showing testscript name and line number
测试用例文件:
import os
import sys
import pytest
import logging
LOGGER = logging.getLogger(__name__)
def test_one():
print('')
print("(test_one) TEST1")
LOGGER.info("(test_two) INFO1:")
LOGGER.warning("(test_two) WARNING1:")
LOGGER.error("(test_two) ERROR1:")
LOGGER.critical("(test_two) CRITICAL1:")
apple = 'red'
assert apple == 'red'
def test_two():
print('')
print("(test_two) TEST2")
LOGGER.info("(test_two) INFO2:")
LOGGER.warning("(test_two) WARNING2:")
LOGGER.error("(test_two) ERROR2:")
LOGGER.critical("(test_two) CRITICAL2:")
pear = 'green'
assert pear == 'green'
日志文件:
[pytest]
log_cli = 1
log_cli_level = DEBUG
log_cli_format = %(message)s
log_file = logs/pytest.log
log_file_level = DEBUG
log_file_format = %(asctime)s %(levelname)8s: %(message)s
log_file_date_format=%Y%m%d%H%M%S
日志文件输出:
20200611090159 INFO: (test_two) INFO1:
20200611090159 WARNING: (test_two) WARNING1:
20200611090159 ERROR: (test_two) ERROR1:
20200611090159 CRITICAL: (test_two) CRITICAL1:
20200611090159 INFO: (test_two) INFO2:
20200611090159 WARNING: (test_two) WARNING2:
20200611090159 ERROR: (test_two) ERROR2:
20200611090159 CRITICAL: (test_two) CRITICAL2:
【问题讨论】:
标签: logging pytest-html