Skip to content
Advertisement

Assert exception message?

I’m using pytest in a project with a good many custom exceptions.

pytest provides a handy syntax for checking that an exception has been raised, however, I’m not aware of one that asserts that the correct exception message has been raised.

Say I had a CustomException that prints “boo!”, how could I assert that “boo!” has indeed been printed and not, say, “<unprintable CustomException object>”?

JavaScript
JavaScript

Advertisement

Answer

I think what you’re looking for is:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement