Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If there is a need to have access to the actual exception info the Pytest context manager optionally lets you add as 'your_text' like in the example below. "'exception_info" is an ExceptionInfo instance' is an ExceptionInfo instance, which is a wrapper around the actual exception raised. The main attributes of interest are .type.value and value and .traceback.

Code Block
languagepy
import pytest
from sources.operations import divide


def test_division_by_zero_with_exception_info():
    with pytest.raises(ZeroDivisionError) as exception_info:
        division(1, 0)
    assert "division by zero" in str(exception_info.value)

...