Closed edouard-lopez closed 5 years ago
It seems the problem is linked to pytest. The assertion is True in a python interpreter, False in pytest:
Python 3.7.2+ (default, Feb 2 2019, 14:31:48)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import prompt
>>> str(prompt.prompt_symbol()) == '\x1b[38;2;155;48;255m' + prompt.sup + '\x1b[39m'
True
I made some changes to the example code:
prompt.py:
import colors
sup = '❯'
def prompt_symbol():
return colors.primary(sup)
colors_test.py:
import colors
import prompt
def test_prompt_symbol_is_colored_for_successful_command():
assert str(prompt.prompt_symbol()) == str(colors.primary(prompt.sup))
assert str(prompt.prompt_symbol()) == '\x1b[38;2;155;48;255m' + prompt.sup + '\x1b[39m'
@timofurrer @Krilivye suggested to try --capture=no
(or -s
) flag from pytest
.
That does fix my problem when running pytest -v --capture=no tests/
, but I don't get why as I don't print to stdout
nor stderr
in the tested method.
Moreover it doesn't work when I use it through a makefile make tests
:
tests:
clear
pytest --verbose --capture=no tests/
To fix the makefile, I move colorful.use_true_colors()
from prompt.py to colors.py
It's because colorful disables colors automatically when it's piped into another stream.
@timofurrer Is it possible to disable this behavior other than the solution I used ?
related: https://stackoverflow.com/q/54884561/802365
I'm re-implementing pure prompt in python so it can support more shell.
However, when testing color I got "unexecpected" behavior, i.e. one that I don't understand.
tests output
_colorstest.py
colors.py
prompt.py
Question
The first assertion succeed, while the second failed despite the fact they should be equivalent. When I negate the first assertion the escape sequence are not present:
Manually executing command in python REPL gives me: