[issue18573] In unittest.TestCase.assertWarns doc there is some text about assertRaises()
New submission from py.user: http://docs.python.org/3/library/unittest.html#unittest.TestCase.assertWarns "When used as a context manager, assertRaises() accepts" "... is to perform additional checks on the exception raised" ---------- assignee: docs@python components: Documentation files: issue.diff keywords: patch messages: 193788 nosy: docs@python, py.user priority: normal severity: normal status: open title: In unittest.TestCase.assertWarns doc there is some text about assertRaises() type: enhancement versions: Python 3.4 Added file: http://bugs.python.org/file31054/issue.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18573> _______________________________________
Changes by Terry J. Reedy <tjreedy@udel.edu>: ---------- stage: -> needs patch versions: +Python 2.7, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18573> _______________________________________
Changes by Terry J. Reedy <tjreedy@udel.edu>: ---------- assignee: docs@python -> terry.reedy nosy: +terry.reedy _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18573> _______________________________________
Roundup Robot added the comment: New changeset 55dcf9e065be by Terry Jan Reedy in branch '3.3': Issue #18573: Complete copy-paste from assertRaises entry to assertWarns entry. http://hg.python.org/cpython/rev/55dcf9e065be ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18573> _______________________________________
Terry J. Reedy added the comment: assertWarns is new in 3.2 and not in 2.7. The sentence was copied from the assertRaises section but not changed. Thanks for reporting. ---------- resolution: -> fixed stage: needs patch -> committed/rejected status: open -> closed type: enhancement -> behavior versions: -Python 2.7 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18573> _______________________________________
py.user added the comment: What about the second line? It doesn't catch any exception utest.py #!/usr/bin/env python3 import unittest class Test(unittest.TestCase): def test_warning(self): import warnings with self.assertWarns(RuntimeWarning) as cm: raise ValueError('f') warnings.warn('f', RuntimeWarning) print(repr(cm.warning)) [guest@localhost py]$ python3 -m unittest utest E ====================================================================== ERROR: test_warning (utest.Test) ---------------------------------------------------------------------- Traceback (most recent call last): File "./utest.py", line 11, in test_warning raise ValueError('f') ValueError: f ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (errors=1) [guest@localhost py]$ with commented raise [guest@localhost py]$ python3 -m unittest utest RuntimeWarning('f',) . ---------------------------------------------------------------------- Ran 1 test in 0.000s OK [guest@localhost py]$ in the patch I copied terms from the first sentence of the paragraph ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18573> _______________________________________
Terry J. Reedy added the comment:
What about the second line? What second line? It doesn't catch any exception It? I do not understand your point. Your example works as documented, including "any unexpected exception is an error".
Actually, that should be 'any exception' as none is expected. Also, "additional checks on the exception raised:" should be 'warning caught' ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18573> _______________________________________
Roundup Robot added the comment: New changeset 366beee880aa by Terry Jan Reedy in branch '3.3': Issue #18573: More copy-paste fixes to assertWarns entry. http://hg.python.org/cpython/rev/366beee880aa ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18573> _______________________________________
What second line?
py.user added the comment: the second line patched in the diff file ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18573> _______________________________________
participants (3)
-
py.user
-
Roundup Robot
-
Terry J. Reedy