pytest.raises(), how to access the original exception object #8011
-
I expect that a block will raise an exception, and I want to look at the exception's attributes.
Can I access the original exception object stored somewhere in pytest_e?
Am I missing something obvious? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @ruck94301,
with pytest.raises(subprocess.CalledProcessError) as pytest_e:
result = subprocess.check_output(auditcmd)
logger.debug(str(pytest_e.value)) See https://docs.pytest.org/en/stable/reference.html#pytest._code.ExceptionInfo.value. |
Beta Was this translation helpful? Give feedback.
Hi @ruck94301,
exc_info.value
contains the original exception object:See https://docs.pytest.org/en/stable/reference.html#pytest._code.ExceptionInfo.value.