Skip to content

pytest.raises(), how to access the original exception object #8011

Answered by nicoddemus
ruck94301 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @ruck94301,

exc_info.value contains the original exception object:

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.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ruck94301
Comment options

Answer selected by ruck94301
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants