pytest colored output (with --color=yes) makes the test output log unreadable (by humans)
See original GitHub issueVS Code version
1.62.3
Extension version
v2021.11.1422169775
OS type
macOS
OS version
12.0
Python distribution
Other
Python version
3.9
Language server
Pylance
Expected behaviour
I expect the output log in “Python Test Log” to not display the control characters, for instance by stripping them, that is obtaining the following output:
============================= test session starts ==============================
platform darwin -- Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-0.13.1
rootdir: /Users/ogrisel/code/scikit-learn, configfile: setup.cfg
plugins: anyio-3.3.0, xdist-2.3.0, timeout-1.4.2, forked-1.3.0
collected 1 item
sklearn/impute/tests/test_base.py . [100%]
- generated xml file: /var/folders/_y/lfnx34p13w3_sr2k12bjb05w0000gn/T/tmp-17017Jlww71GJ2jF6.xml -
============================== 1 passed in 0.07s ===============================
Alternatively, colors could be rendered in the log as they are when running the tests in a shell terminal:
Actual behaviour
The “Python Test Log” displays the color control characters such as [32m
without rendering them:
[1m============================= test session starts ==============================[0m
platform darwin -- Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-0.13.1
rootdir: /Users/ogrisel/code/debugpytestvscode, configfile: setup.cfg
plugins: anyio-3.3.0, xdist-2.3.0, timeout-1.4.2, forked-1.3.0
collected 1 item
test_debug_vscode.py [32m.[0m[32m [100%][0m
- generated xml file: /var/folders/_y/lfnx34p13w3_sr2k12bjb05w0000gn/T/tmp-24919mvRdR0hh0QGh.xml -
[32m============================== [32m[1m1 passed[0m[32m in 0.01s[0m[32m ===============================[0m
Steps to reproduce
Create a new test Python test project, configure a Python interpreter with pytest installed and add a setup.cfg
file containing:
[aliases]
test = pytest
[tool:pytest]
addopts = --color=yes
and a test file with a single test function, for instance a file named test_debug_vscode.py
with the following content:
def test_donothing_but_pass():
assert True
Then:
Shift-Ctrl-P > Python: Configure Tests > pytest > Use existing config file setup.cfg
Then launch the test by clicking on the green >
icon in the VS Code UI and open the “Python Test Log” output view.
Logs
The Python log itself has no problem:
> ~/mambaforge/envs/dev/bin/python -m pytest --rootdir ~/code/debugpytestvscode --override-ini junit_family=xunit1 --junit-xml=/var/folders/_y/lfnx34p13w3_sr2k12bjb05w0000gn/T/tmp-24919pLfLJqAh0u2i.xml
cwd: ~/code/debugpytestvscode
Code of Conduct
- I agree to follow this project’s Code of Conduct
Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:5 (2 by maintainers)
Top GitHub Comments
@ogrisel I see, thanks for clarifying.
Parsing is not the problem: the test runner can complete successfully with green markers everywhere. It’s just the display in the “Python Test Log” output view that is unreadable.