A pytest plugin for colorful print statements.
pip install pytest-crayons
- Include a color fixture in the param list of a test.
- Then use it instead of
print
.
def test_magenta(magenta):
magenta("this should be magenta")
Just like normal print statements, you only see the output if:
- There's an failure in the test.
- or you pass in
-s
or--capture=no
- or you wrap the statement in a
with capsys.disabled():
block.
For our examples, we'll use -s
:
- red
- green
- yellow
- blue
- magenta
- cyan
Example with all colors:
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")
- Conference talk page : Sharing is Caring - Sharing pytest Fixtures