跳转到主要内容

一个用于彩色打印语句的pytest插件

项目描述

pytest-crayons

一个用于彩色打印语句的pytest插件。

安装

pip install pytest-crayons

使用

  1. 在测试的参数列表中包含一个颜色设置。
  2. 然后用它来代替 print
def test_magenta(magenta):
    blue("this should be magenta")

就像正常的打印语句一样,只有在以下情况下你才能看到输出:

  • 测试中存在失败。
  • 或者你传递了 -s--capture=no
  • 或者你用 with capsys.disabled(): 块包裹语句。

在我们的例子中,我们将使用 -s

output of test_something

可用颜色

  • 红色
  • 绿色
  • 黄色
  • 蓝色
  • 品红色
  • 青色

所有颜色的示例

def test_colors(red, green, yellow, blue, magenta, cyan):
    print("") # for the newline
    red("this should be red")
    green("this should be green")
    yellow("this should be yellow")
    blue("this should be blue")
    magenta("this should be magenta")
    cyan("this should be cyan")

output of test_colors

这被包含在PyCascades 2023的演讲中

项目详情


下载文件

下载适合您平台的文件。如果您不确定要选择哪个,请了解更多关于安装包的信息。

源分布

pytest-crayons-0.0.7.tar.gz (93.3 kB 查看哈希值)

上传时间:

构建分布

pytest_crayons-0.0.7-py3-none-any.whl (4.0 kB 查看散列值)

上传于 Python 3

支持者