Issue 32971: Docs on unittest.TestCase.assertRaises() should clarify context manager details (original) (raw)
Issue32971
Created on 2018-02-28 17:58 by nodakai, last changed 2022-04-11 14:58 by admin. This issue is now closed.
Messages (2) | ||
---|---|---|
msg313061 - (view) | Author: NODA Kai (nodakai) | Date: 2018-02-28 17:58 |
https://docs.python.org/dev/library/unittest.html#unittest.TestCase.assertRaises > If only the exception and possibly the msg arguments are given, return a context manager so that the code under test can be written inline rather than as a function: > > with self.assertRaises(SomeException): do_something() > > When used as a context manager, assertRaises() accepts the additional keyword argument msg. Perhaps we don't need the second sentence on the `msg` argument which isn't adding anything new. Ideally it should be more clear when the method operates in context manager mode. ("If only" and "possibly" don't play nicely together.) Maybe along the lines of "If no callable was passed as an argument ..." ? I haven't looked in to the actual implementation yet... | ||
msg313619 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
Date: 2018-03-11 19:28 |
The implementation is literally that no non-keyword arguments other than the exception are given. If any keyword arguments other than msg are given, you get a warning. To say just "no callable" would be about as confusing as the 'and possibly' given the documented prototype, since in fact any non-keyword argument will be assumed to be the callable. So the text is correct as written, and I'm not sure how one would make it clearer and still be technically correct. But further suggestions are welcome. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:58:58 | admin | set | github: 77152 |
2019-05-06 20:20:48 | anthonypjshaw | set | status: open -> closedstage: patch review -> resolved |
2019-05-06 20:19:49 | anthonypjshaw | set | pull_requests: - <pull%5Frequest9605> |
2018-11-02 11:25:06 | dave-shawley | set | keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest9605> |
2018-03-11 19:28:39 | r.david.murray | set | nosy: + r.david.murraymessages: + |
2018-03-01 21:42:19 | brett.cannon | set | title: Docs on unittest.TestCase.assertRaises() should be improved -> Docs on unittest.TestCase.assertRaises() should clarify context manager details |
2018-02-28 18:02:20 | serhiy.storchaka | set | nosy: + ezio.melotti |
2018-02-28 17:59:16 | nodakai | set | title: unittest.TestCase.assertRaises -> Docs on unittest.TestCase.assertRaises() should be improved |
2018-02-28 17:58:02 | nodakai | create |