Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing a way to use assertRaises as context manager #113

Closed
petrblaho opened this issue Oct 23, 2014 · 2 comments
Closed

missing a way to use assertRaises as context manager #113

petrblaho opened this issue Oct 23, 2014 · 2 comments

Comments

@petrblaho
Copy link

I think that it would be useful if we can use assertRaises as context manager the same way as in unittest.
That way allows to organize code better (block of code) and store raised exception to variable for further inspection.

@jml
Copy link
Member

jml commented Oct 23, 2014

FWIW, you can use assertRaises like this:

e = self.assertRaises(RuntimeException, f, x, y)
self.assertEqual("Some error", str(e))

I personally prefer the way we have it now. It's possible that compatibility is a stronger goal.

@petrblaho
Copy link
Author

Thanks for reply, @jml .

I did not realized it can be solved this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants