okken / pytest-check

A pytest plugin that allows multiple failures per test.
MIT License
349 stars 35 forks source link

Add possibility to print full trace #124

Closed Le0nRoy closed 1 year ago

Le0nRoy commented 1 year ago

Sometimes it is required to see all traces instead of pseudo-trace only. So it would be great to have possibility to configure what output should be printed

okken commented 1 year ago

I'm not sure I'd like the complexity that would add to the code. However, I'm willing to consider, if you have an example of how it could be implemented.

Le0nRoy commented 1 year ago

I have made a small workaround in my project, that allows to print full assertions:

def soft_assert(msg: str = None):
    """
    Wrapper over `pytest_check.check` that allows to print full
    traceback instead of pseudo-traceback implemented in package
    Should be used like:
with soft_assert():
    assert False
```
:param msg: message that will be printed in the beginning of the trace
"""
try:
    yield
except Exception as e:
    exc_type = type(e)
    exc_val = "".join(traceback.format_exception(exc_type, e, e.__traceback__))
    with check(msg):
        raise type(e)(exc_val)


It is not elegant solution, however it works. Later I will check how it could be implemented inside your lib as a flag
okken commented 1 year ago

some changes coming in 2.2.0, not huge changes, but I'm incorporating the full traceback information

okken commented 1 year ago

2.2.0 is published

Le0nRoy commented 1 year ago

Thank you!