[issue18566] In unittest.TestCase docs for setUp() and tearDown() don't mention AssertionError
New submission from py.user: http://docs.python.org/3/library/unittest.html#unittest.TestCase.setUp "any exception raised by this method will be considered an error rather than a test failure" http://docs.python.org/3/library/unittest.html#unittest.TestCase.tearDown "Any exception raised by this method will be considered an error rather than a test failure." utest.py #!/usr/bin/env python3 import unittest class Test(unittest.TestCase): def setUp(self): raise AssertionError def tearDown(self): raise AssertionError def test_nothing(self): pass [guest@localhost py]$ python3 -m unittest -v utest test_nothing (utest.Test) ... FAIL ====================================================================== FAIL: test_nothing (utest.Test) ---------------------------------------------------------------------- Traceback (most recent call last): File "./utest.py", line 8, in setUp raise AssertionError AssertionError ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (failures=1) [guest@localhost py]$ also raising unittest.SkipTest works properly ---------- assignee: docs@python components: Documentation messages: 193772 nosy: docs@python, py.user priority: normal severity: normal status: open title: In unittest.TestCase docs for setUp() and tearDown() don't mention AssertionError type: enhancement versions: Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- keywords: +easy nosy: +ezio.melotti, michael.foord stage: -> needs patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Terry J. Reedy added the comment: I re-ran with setUp 'raise' changed to 'pass' to see the effect of raise AssertionError or unittest.SkipTest in tearDown and indeed the test fails or skips even then. I suggest adding ', other than AssertionError or SkipTest,' just after 'method'. The same is true of test_xxx methods. A slight anomaly is that AssertionError in test_nothing and SkipTest in tearDown results in "FAILED (failures=1, skipped=1)", which is not really a skip. For setUpClass and setUpModule, AssertionErrors *are* errors, not failures, while SkipTest works everywhere. ---------- nosy: +terry.reedy versions: +Python 2.7, Python 3.3 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Changes by Phil Connell <pconnell@gmail.com>: ---------- nosy: +pconnell _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Julian Gindi added the comment: I did some further testing and it seems that you are right, testcase.SkipTest() never causes an error in setUp or tearDown but "raise AssertionError" does (even in setUp or tearDown). I went ahead and made relevant documentation changes, let me know what you think. ---------- keywords: +patch nosy: +Julian.Gindi Added file: http://bugs.python.org/file32716/issue18566.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Julian Gindi added the comment: Looks like this issue has been resolved. Can we close it? ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Terry J. Reedy added the comment: Resolved in what way? The doc seems unchanged. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Julian Gindi added the comment: Sorry. I meant, merged. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
py.user added the comment: I have built 3.4.0a4 and run - same thing ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Michael Foord added the comment: Yep, those docs are just wrong. I'm trying to think of a concise rewording. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Changes by Sreepriya Chalakkal <sreepriya1111@gmail.com>: Added file: http://bugs.python.org/file34420/doc18566.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
py.user added the comment: In proposed patches fix Skiptest -> :exc:`SkipTest` AssertionError -> :exc:`AssertionError` ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Nitika Agarwal added the comment: Hi, I am attaching a patch with the changes made as suggested by py.user. ---------- nosy: +nitika Added file: http://bugs.python.org/file34550/document18566.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Nitika Agarwal added the comment: Hi, Please review the patch attached. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Michael Foord added the comment: Patch looks good to me. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Changes by Terry J. Reedy <tjreedy@udel.edu>: ---------- assignee: docs@python -> terry.reedy _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Roundup Robot added the comment: New changeset fdadc152b964 by Terry Jan Reedy in branch '2.7': Issue #18566: Clarify unittest setUp, tearDown doc. Patch by Nitika Agarwal. http://hg.python.org/cpython/rev/fdadc152b964 New changeset 9ab66a7f654a by Terry Jan Reedy in branch '3.4': Issue #18566: Clarify unittest setUp, tearDown doc. Patch by Nitika Agarwal. http://hg.python.org/cpython/rev/9ab66a7f654a New changeset 72b1715e18c1 by Terry Jan Reedy in branch '2.7': #18566: Whitespace http://hg.python.org/cpython/rev/72b1715e18c1 New changeset a37440dec1b6 by Terry Jan Reedy in branch '3.4': #18566: Whitespace http://hg.python.org/cpython/rev/a37440dec1b6 ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Terry J. Reedy added the comment: Nitika, congrats on first patch. One minor problem: spaces at end of lines. It it my fault for not checking, but try to avoid them anyway. ---------- resolution: -> fixed stage: needs patch -> committed/rejected status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
Nitika Agarwal added the comment: @Terry J.Reedy Thanks a lot.And yes, I will take care of it next time. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue18566> _______________________________________
participants (9)
-
Ezio Melotti
-
Julian Gindi
-
Michael Foord
-
Nitika Agarwal
-
Phil Connell
-
py.user
-
Roundup Robot
-
Sreepriya Chalakkal
-
Terry J. Reedy