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

unittest - use contexts to assert exceptions #48694

Closed
dleonard0 mannequin opened this issue Nov 27, 2008 · 3 comments
Closed

unittest - use contexts to assert exceptions #48694

dleonard0 mannequin opened this issue Nov 27, 2008 · 3 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@dleonard0
Copy link
Mannequin

dleonard0 mannequin commented Nov 27, 2008

BPO 4444
Nosy @pitrou
Files
  • unittest.patch: patych to unittest.py
  • 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 = None
    closed_at = <Date 2008-12-28.14:29:38.952>
    created_at = <Date 2008-11-27.09:49:59.368>
    labels = ['type-feature', 'library']
    title = 'unittest - use contexts to assert exceptions'
    updated_at = <Date 2008-12-28.14:29:38.951>
    user = 'https://bugs.python.org/dleonard0'

    bugs.python.org fields:

    activity = <Date 2008-12-28.14:29:38.951>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-12-28.14:29:38.952>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2008-11-27.09:49:59.368>
    creator = 'dleonard0'
    dependencies = []
    files = ['12138']
    hgrepos = []
    issue_num = 4444
    keywords = ['patch']
    message_count = 3.0
    messages = ['76492', '76500', '78404']
    nosy_count = 3.0
    nosy_names = ['purcell', 'pitrou', 'dleonard0']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue4444'
    versions = ['Python 3.0']

    @dleonard0
    Copy link
    Mannequin Author

    dleonard0 mannequin commented Nov 27, 2008

    Patch to allow unit tests to test for exceptions through a 'with'
    statement. Resulting (failing) test would look like this:

      import unittest
    
      class T(unittest.TestCase):
         def runTest(self):
            with self.assertRaises(KeyError):
               raise ValueError

    This saves having to put exception raising tests into a try/except
    block, which is cool. And by cool I mean totally sweet.

    @dleonard0 dleonard0 mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Nov 27, 2008
    @purcell
    Copy link
    Mannequin

    purcell mannequin commented Nov 27, 2008

    I like this change, since assertRaises can be a bit messy when passing it
    a local function.

    I'd suggest modifying the patch such that the AssertRaisesContext class is
    also used when callableObj is provided, which would eliminate the
    duplication of the code that checks for exceptions.

    @pitrou
    Copy link
    Member

    pitrou commented Dec 28, 2008

    I've committed an improved patch, with tests and doc, in r67979 and
    r67981. Thanks!

    @pitrou pitrou closed this as completed Dec 28, 2008
    @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
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant