hm, I have just realized I cannot disable colors i...
# general
f
hm, I have just realized I cannot disable colors in the output of
pytest
run? Has anyone been successful in disabling colored output from
pytest
? ๐Ÿงต
Repo: https://github.com/pantsbuild/example-python Disabling colors running pytest directly (no colors are shown)
Copy code
$ pytest --color=no helloworld/greet/greeting_test.py

=================================================================================================== test session starts ====================================================================================================
platform linux -- Python 3.11.3, pytest-7.4.0, pluggy-1.2.0
rootdir: /home/alexey.tereshenkov/code/example-python
plugins: vcr-1.0.2
collected 1 item                                                                                                                                                                                                           

helloworld/greet/greeting_test.py .                                                                                                                                                                                  [100%]

==================================================================================================== 1 passed in 0.05s =====================================================================================================
Attempt to disable colors (colors are still shown)
Copy code
$ pants --pytest-args="--color=no" test --debug ::

=================================================================================================== test session starts ====================================================================================================
platform linux -- Python 3.9.17, pytest-7.0.1, pluggy-1.0.0
rootdir: /tmp/pants-sandbox-cMkXEZ
plugins: cov-3.0.0, xdist-2.5.0, forked-1.6.0
collected 1 item                                                                                                                                                                                                           

helloworld/greet/greeting_test.py .                                                                                                                                                                                  [100%]

==================================================================================================== 1 passed in 0.04s =====================================================================================================
=================================================================================================== test session starts ====================================================================================================
platform linux -- Python 3.9.17, pytest-7.0.1, pluggy-1.0.0
rootdir: /tmp/pants-sandbox-40b0vG
plugins: cov-3.0.0, xdist-2.5.0, forked-1.6.0
collected 3 items                                                                                                                                                                                                          

helloworld/translator/translator_test.py ...                                                                                                                                                                         [100%]

==================================================================================================== 3 passed in 0.01s =====================================================================================================
I can see that the option is passed to the pytest runner in Pants:
Copy code
$ pants --pytest-args="--color=foo" test ::

14:52:46.09 [WARN] Failed to generate JUnit XML data for helloworld/greet/greeting_test.py:tests.
14:52:46.09 [ERROR] Completed: Run Pytest - helloworld/greet/greeting_test.py:tests - failed (exit code 4).
ERROR: usage: pex [options] [file_or_dir] [file_or_dir] [...]
pex: error: argument --color: invalid choice: 'foo' (choose from 'yes', 'no', 'auto')


14:52:46.11 [WARN] Failed to generate JUnit XML data for helloworld/translator/translator_test.py:tests.
14:52:46.11 [ERROR] Completed: Run Pytest - helloworld/translator/translator_test.py:tests - failed (exit code 4).
ERROR: usage: pex [options] [file_or_dir] [file_or_dir] [...]
pex: error: argument --color: invalid choice: 'foo' (choose from 'yes', 'no', 'auto')



โœ• helloworld/greet/greeting_test.py:tests failed in 0.12s.
โœ• helloworld/translator/translator_test.py:tests failed in 0.13s.
s
I don't see colors with this
pants --no-colors --pytest-args="--color=no" test ::
b
The pants https://www.pantsbuild.org/2.20/reference/global-options#colors option should be able to disable pants printing colours to the console globally (although the underlying pytest output still has colours by default, to have better cache-hit rates)