配置为测试结果显示的符号
pytest-custom-report的Python项目详细描述
pytest自定义报告
一个插件,用于定义在pytest中显示测试结果时要使用的自己的字符(通过、失败、跳过等)。
例如,如果希望在每个失败测试的终端报告中显示PILE OF POO (U+1F4A9)标志符号:
pytest --report-failed=?
若要保留自定义字符,请在configuration file(即在pytest.ini、tox.ini、setup.cfg或其他位置)中添加类似的节:
[pytest] report_failed = ? report_failed_verbose = OH CRAP
安装和使用
pip install pytest-custom-report
这将向pytest添加新的命令行参数和配置文件选项(详细信息请参见下一节)。命令行参数优先于配置文件设置。插件总是启用的,但是除非您配置了自己的符号,否则将使用pytest默认值。
要在暂时禁用插件的情况下执行测试,请使用以下命令:
pytest -p no:pytest-custom-report
如果您尝试使用emojis,但在终端中看不到标志符号,则可能缺少带有上平面的unicode字体-您可以安装例如GNU Unifont。
配置
下表显示了每个结果的可用选项以及pytest的默认样式。
test outcome | command-line argument name | .ini file config key | default report symbol |
---|---|---|---|
^{tt7}$ | ^{tt8}$ | ^{tt9}$ | ^{tt10}$ |
^{tt11}$ | ^{tt12}$ | ^{tt13}$ | ^{tt14}$ |
^{tt15}$ | ^{tt16}$ | ^{tt17}$ | ^{tt18}$ |
^{tt19}$ | ^{tt20}$ | ^{tt21}$ | ^{tt22}$ |
^{tt23}$ | ^{tt24}$ | ^{tt25}$ | ^{tt26}$ |
^{tt27}$ | ^{tt28}$ | ^{tt29}$ | ^{tt30}$ |
当在启用-v或--verbose标志的情况下执行测试时,将显示更长的字符串,每个测试结果显示一行。这些也可以指定。
test outcome | command-line argument name | .ini file config key | default report string |
---|---|---|---|
^{tt7}$ | ^{tt34}$ | ^{tt35}$ | ^{tt36}$ |
^{tt11}$ | ^{tt38}$ | ^{tt39}$ | ^{tt40}$ |
^{tt15}$ | ^{tt42}$ | ^{tt43}$ | ^{tt44}$ |
^{tt19}$ | ^{tt46}$ | ^{tt47}$ | ^{tt48}$ |
^{tt23}$ | ^{tt50}$ | ^{tt51}$ | ^{tt52}$ |
^{tt27}$ | ^{tt54}$ | ^{tt55}$ | ^{tt56}$ |
示例配置文件
下面是一些示例pytest.ini内容,您可以根据自己的喜好复制粘贴和修改:
[pytest] report_passed = ✔ report_xpassed = ? report_failed = ✗ report_xfailed = ? report_skipped = ? report_error = ? report_passed_verbose = OH YEAH report_xpassed_verbose = WHAT IN TARNATION? report_failed_verbose = OH CRAP report_xfailed_verbose = YEAH WHATEVER report_skipped_verbose = DON'T CARE report_error_verbose = YOU MEDDLING KIDS!