【问题标题】:pytest-html: Get rid of ASCII in capture log, so it doesn't show details link, when using logging?pytest-html:在捕获日志中删除 ASCII,因此在使用日志记录时它不显示详细信息链接?
【发布时间】: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


    【解决方案1】:

    找到我的答案:不要使用日志系统在显示详细信息链接中打印消息。如果从命令行运行它,则会出现 ASCII 字符。 无论您如何运行它,报告都会显示测试脚本的名称和行号。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-18
      • 1970-01-01
      • 2016-01-21
      • 1970-01-01
      相关资源
      最近更新 更多