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? |
Answered by
nicoddemus
Nov 8, 2020
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. |
1 reply
Answer selected by
ruck94301
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @ruck94301,
exc_info.valuecontains the original exception object:See https://docs.pytest.org/en/stable/reference.html#pytest._code.ExceptionInfo.value.