Issue 28135: assertRaises should return the exception in its simple form (original) (raw)
Issue28135
Created on 2016-09-13 20:12 by facundobatista, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (3) | ||
---|---|---|
msg276334 - (view) | Author: Facundo Batista (facundobatista) * ![]() |
Date: 2016-09-13 20:12 |
So, you could do: exc = self.assertRaises(ValueError, somefunc, someargs) And then, explore "exc" as will. Yes, you can get the exception if you use assertRaises as a context manager, but that leads to more cumbersome code: with self.assertRaises(ValueError) as cm: somefunc(someargs) exc = cm.exception | ||
msg276454 - (view) | Author: Raymond Hettinger (rhettinger) * ![]() |
Date: 2016-09-14 14:13 |
-0 This doesn't feel Pythonic to me. | ||
msg276458 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
Date: 2016-09-14 14:44 |
This has been proposed and rejected several times before. IMO, a strong reason to reject it is that no other assert methods return values. Consistency is important. Also note that cm survives the context manager, so you don't need that assignment statement. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:58:36 | admin | set | github: 72322 |
2018-01-03 16:11:31 | r.david.murray | link | issue32487 superseder |
2016-09-14 14:44:34 | r.david.murray | set | status: open -> closedsuperseder: unittest.assertRaises() return the raised exceptionnosy: + r.david.murraymessages: + resolution: duplicatestage: resolved |
2016-09-14 14:13:58 | rhettinger | set | nosy: + rhettingermessages: + |
2016-09-13 20:12:11 | facundobatista | create |