aurzenligl / pytest-logger

Pytest plugin configuring handlers for loggers from Python logging module.
MIT License
35 stars 11 forks source link

storing output of failures #34

Closed krzysiek6d closed 9 months ago

krzysiek6d commented 9 months ago

Hi

I'm using pytest-logger and I have example test:

def test_random():
    import random
    assert random.choice([1,2,3,4]) == 2

Of course this test fails sometimes. The output of assertion is only printed to stdout/err.

test_random.py F                                                                                                                                                        [100%]

==================================================================================================== FAILURES =====================================================================================================
___________________________________________________________________________________________________ test_random ___________________________________________________________________________________________________
test_random.py:49: in test_random
    assert random.choice([1,2,3,4]) == 2
E   AssertionError: assert 1 == 2
E    +  where 1 = <bound method Random.choice of <random.Random object at 0x28b5a78>>([1, 2, 3, 4])
E    +    where <bound method Random.choice of <random.Random object at 0x28b5a78>> = <module 'random' from '/usr/lib/python3.6/random.py'>.choice
============================================================================================= short test summary info =============================================================================================
FAILED test_random::test_random - AssertionError: assert 1 == 2
======================================================================================== 1 failed, 544 deselected in 1.51s ========================================================================================
ERROR: InvocationError for command .tox/super_test/bin/py.test -n auto -raR --tb=short --sut-name=auto -k test_random -n0 (exited with code 1)
_____________________________________________________________________________________________________ summary _____________________________________________________________________________________________________
ERROR:   super_test: commands failed

Is it possible to store such output in logs for each failed test? How to do that? This would be very helpful to analyze issues. Currently there are only files created by pytest-logger itself and they do not contain such exceptions.

krzysiek6d commented 9 months ago

I managed to do that with some pytest hooks with similar approach as there: https://py.watch/pytest-save-full-error-output-to-file-ee37d6ccbd32

I don't need your help there, have a nice day! ;)

aurzenligl commented 9 months ago

True, I think it's easier to store that part of status pytest output using other hooks. Good day :)