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

In unittest.TestCase docs for setUp() and tearDown() don't mention AssertionError #62766

Closed
py-user mannequin opened this issue Jul 27, 2013 · 15 comments
Closed

In unittest.TestCase docs for setUp() and tearDown() don't mention AssertionError #62766

py-user mannequin opened this issue Jul 27, 2013 · 15 comments
Assignees
Labels
docs Documentation in the Doc dir easy type-feature A feature request or enhancement

Comments

@py-user
Copy link
Mannequin

py-user mannequin commented Jul 27, 2013

BPO 18566
Nosy @terryjreedy, @ezio-melotti, @voidspace, @py-user, @phmc
Files
  • issue18566.patch
  • doc18566.patch: Adding doc for AssertionError and Skiptest exception
  • document18566.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/terryjreedy'
    closed_at = <Date 2014-04-16.03:47:01.203>
    created_at = <Date 2013-07-27.05:12:17.037>
    labels = ['easy', 'type-feature', 'docs']
    title = "In unittest.TestCase docs for setUp() and tearDown() don't mention AssertionError"
    updated_at = <Date 2014-04-16.19:40:03.000>
    user = 'https://github.com/py-user'

    bugs.python.org fields:

    activity = <Date 2014-04-16.19:40:03.000>
    actor = 'nitika'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2014-04-16.03:47:01.203>
    closer = 'terry.reedy'
    components = ['Documentation']
    creation = <Date 2013-07-27.05:12:17.037>
    creator = 'py.user'
    dependencies = []
    files = ['32716', '34420', '34550']
    hgrepos = []
    issue_num = 18566
    keywords = ['patch', 'easy']
    message_count = 15.0
    messages = ['193772', '193796', '203454', '206928', '206929', '206930', '206931', '207087', '213668', '214379', '215618', '216375', '216427', '216428', '216563']
    nosy_count = 9.0
    nosy_names = ['terry.reedy', 'ezio.melotti', 'michael.foord', 'docs@python', 'py.user', 'python-dev', 'pconnell', 'Julian.Gindi', 'nitika']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue18566'
    versions = ['Python 2.7', 'Python 3.3', 'Python 3.4']

    @py-user
    Copy link
    Mannequin Author

    py-user mannequin commented Jul 27, 2013

    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

    @py-user py-user mannequin assigned docspython Jul 27, 2013
    @py-user py-user mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Jul 27, 2013
    @terryjreedy
    Copy link
    Member

    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.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Nov 20, 2013

    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.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Dec 25, 2013

    Looks like this issue has been resolved. Can we close it?

    @terryjreedy
    Copy link
    Member

    Resolved in what way? The doc seems unchanged.

    @JulianGindi
    Copy link
    Mannequin

    JulianGindi mannequin commented Dec 25, 2013

    Sorry. I meant, merged.

    @py-user
    Copy link
    Mannequin Author

    py-user mannequin commented Dec 25, 2013

    I have built 3.4.0a4 and run - same thing

    @voidspace
    Copy link
    Contributor

    Yep, those docs are just wrong. I'm trying to think of a concise rewording.

    @py-user
    Copy link
    Mannequin Author

    py-user mannequin commented Mar 15, 2014

    In proposed patches fix

    Skiptest -> :exc:`SkipTest`
    AssertionError -> :exc:`AssertionError`

    @nitika
    Copy link
    Mannequin

    nitika mannequin commented Mar 21, 2014

    Hi,
    I am attaching a patch with the changes made as suggested by py.user.

    @nitika
    Copy link
    Mannequin

    nitika mannequin commented Apr 5, 2014

    Hi,
    Please review the patch attached.

    @voidspace
    Copy link
    Contributor

    Patch looks good to me.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Apr 16, 2014

    New changeset fdadc152b964 by Terry Jan Reedy in branch '2.7':
    Issue bpo-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 bpo-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':
    bpo-18566: Whitespace
    http://hg.python.org/cpython/rev/72b1715e18c1

    New changeset a37440dec1b6 by Terry Jan Reedy in branch '3.4':
    bpo-18566: Whitespace
    http://hg.python.org/cpython/rev/a37440dec1b6

    @terryjreedy
    Copy link
    Member

    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.

    @nitika
    Copy link
    Mannequin

    nitika mannequin commented Apr 16, 2014

    @terry J.Reedy
    Thanks a lot.And yes, I will take care of it next time.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir easy type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants