pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Provide dedicated control over truncation of "short test summary info" lines

Open yarikoptic opened this issue 2 years ago • 3 comments

What's the problem this feature will solve?

Currently we cannot easily grasp the summary of underlying fails/errors which happened on CIs (logs archived using https://github.com/con/tinuous/) because "short test summary info" truncates to the width of the terminal which is in non-interactive session happens to be around 80. So we get just e.g.

(git)smaug:/mnt/datasets/datalad/ci/logs/2022/08[master]git
$> git grep  '^FAIL.*test_gracefull_dea'                               
03/pr/6915/964b1f4/travis-14378-failed/2.txt:FAILED ../datalad/support/tests/test_parallel.py::test_gracefull_death - asse...
03/pr/6915/964b1f4/travis-14378-failed/4.txt:FAILED ../support/tests/test_parallel.py::test_gracefull_death - assert 0 >= 2
23/pr/6958/fa7cee0/travis-14469-failed/9.txt:FAILED ../datalad/support/tests/test_parallel.py::test_gracefull_death - asse...
29/pr/6981/2551844/travis-14510-failed/3.txt:FAILED ../support/tests/test_parallel.py::test_gracefull_death - assert [0, 2...
30/push/maint/870c72a/travis-14519-failed/9.txt:FAILED ../datalad/support/tests/test_parallel.py::test_gracefull_death - asse...

The only workaround I found is to specify explicitly COLUMNS env var to be of some higher value on CI, but that would make the entire log wider, so wider section headers etc.

Ideally I wish there was some pytest setting which would take and not truncate the first line (i.e. split by \n) of that line to be displayed so in the captured logs we have it in its entirety.

yarikoptic avatar Sep 01 '22 17:09 yarikoptic

Perhaps it makes sense for us to detect we are running on CI and not truncate at all? I recall we already do something similar to truncate tracebacks...

nicoddemus avatar Sep 01 '22 18:09 nicoddemus

not sure if worth "on CI" -- the same effect is observed when stdout is not a terminal, i.e. if gets piped to | cat.

yarikoptic avatar Sep 01 '22 18:09 yarikoptic

Fair enough.

nicoddemus avatar Sep 01 '22 18:09 nicoddemus

Can you provide a reproducible example? I'd like to take a stab at this :)

david1542 avatar Oct 21 '22 16:10 david1542

#!/bin/bash
set -x

cd "$(mktemp -d ${TMPDIR:-/tmp}/pytest-XXXXXXX)"

cat >| test_some_path_could_be_long.py <<EOF
def test_short_fail():
    assert False 
def test_veryyyyyyyyy_long_test_name_just_because_no_long_path():
    assert False  # which could be long line too
EOF

python3 -m pytest test_some_path_could_be_long.py 
python3 -m pytest test_some_path_could_be_long.py | cat 

would end with

FAILED test_some_path_could_be_long.py::test_short_fail - assert False
FAILED test_some_path_could_be_long.py::test_veryyyyyyyyy_long_test_name_just_because_no_long_path

so no the assert False like in previous output without | cat

yarikoptic avatar Oct 21 '22 18:10 yarikoptic

ping on this

yarikoptic avatar Mar 13 '23 12:03 yarikoptic

Could we have a flag that just stops the truncation of the summary? I would personally just use that in general, even outside of CI.

tunstek avatar Aug 14 '23 09:08 tunstek