How to test for chained exceptions? #9979
Unanswered
GlenNicholls
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I wrote a JSON schema that defines the expected data structure for a configuration file and I have an exception that gets raised by a third-party package (jsonschema
ValidationError
). The exception value contains info about what attributes failed validation. In my tests, I would like to make sure my schema is properly catching all issues possible. But, I need to tell the user with a new exception which file has the error, and thus, I'm catching this exception and raising a new one that points to the JSON file causing the error. In essence, the following:The problem I'm running into is how do I test that I'm correctly handling each error condition? I would like to make sure that I am matching against the correct
ValidationError
message while running my tests to ensure that my JSON schema is actually defining the attributes of the JSON data correctly. Basically, the below is useless in pytest other than understanding the exception was raised, however, it doesn't test that my schema defined some properties correctly:What I can do is add it to my new error like so:
But this doesn't really solve my issue as critical information may be lost by keeping the value of the third-party error and not the metadata of the traceback.
In short, what I'm asking is how do I check the chained traceback for a specific string/pattern?
pytest.raises
has thematch
keyword, but it only works on the caught exceptions message, not other messages in the traceback.Beta Was this translation helpful? Give feedback.
All reactions