Search code examples
bashshellpytestoh-my-zshiterm2

Why is iTerm2 printing Pytest results in color?


I was playing around with Pytest --color=yes option and realized that my Terminal is printing results in color even without it being set. Why is that?

My terminal setup is this:

  • OS: MacOS
  • iTerm2 build 3.4.15
  • iTerm2 Report terminal type property set to: xterm-256color
  • default shell is zsh (oh-my-zsh)
  • not sure if anything else matters...

My guess is it has something to do with oh-my-zsh, but I am not sure what, where and how.

I got to this question because I was trying to create SublimeText build system that will print results in colors, without success (not counting using SublimeANSI plugin which works with some quirks).

So, to reiterate the question: I am confused why my terminal app is printing Pytest results in color, even when no --color=yes is not set for Pytest.


Solution

  • If we look at the Pytest terminal source, we'll see the following on the color option:

    group._addoption(
        "--color",
        metavar="color",
        action="store",
        dest="color",
        default="auto",
        choices=["yes", "no", "auto"],
        help="color terminal output (yes/no/auto).",
    )
    

    So the default is set to auto.


    Your zsh/oh-my-zsh allows to use the colors and therefore there shown without passing the option yourself.