On Mon, Oct 14, 2013 at 17:19 +0200, Vladimir Keleshev wrote:
> Right now one of my code-bases is filled with assertions like:
>
> with raises(SpecificError) as error:
> some_action()
> assert 'specific message' == str(error)
>
> Why not change `raises` to allow instances of exceptions as well:
>
> with raises(SpecificError('specific message')):
> some_action()
This depends on defining equality on the exception object, i guess.
For example:
>>> KeyError("hello") == KeyError("hello")
False
So it doesn't seem to be defined by default. Of course we could do
something ourselves but i am not sure how reliable that would be.
Experiment if you like :)
holger
> I think, this can improve readability of `raises` assertions. Can't even
> think of immediate downsides of this.
>
> What do you think?
>
> —Vladimir
> _______________________________________________
> Pytest-dev mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/pytest-dev
_______________________________________________
Pytest-dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pytest-dev