Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25416

Re: assertraises behaviour

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feed.xsnews.nl!border-3.ams.xsnews.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; 'context': 0.05; 'bits': 0.07; 'executed': 0.07; 'false,': 0.07; 'raised': 0.07; 'stops': 0.07; 'unittest': 0.07; 'python': 0.09; 'block.': 0.09; 'oserror': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.10; '"should': 0.16; 'fail,': 0.16; 'from:addr:cheimes.de': 0.16; 'from:addr:lists': 0.16; 'from:name:christian heimes': 0.16; 'message-id:@dough.gmane.org': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'import': 0.21; 'doc': 0.22; 'example': 0.23; 'raise': 0.24; 'testing': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'reaches': 0.27; "doesn't": 0.28; 'header:X -Complaints-To:1': 0.28; 'assert': 0.29; 'behaviour': 0.29; 'words': 0.29; 'class': 0.29; '(from': 0.30; 'code': 0.31; 'skip:s 30': 0.33; 'to:addr:python-list': 0.33; 'christian': 0.34; 'expected': 0.35; 'received:org': 0.36; 'but': 0.36; 'should': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'more': 0.63; 'andrea': 0.84; '(running': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Christian Heimes <lists@cheimes.de>
Subject Re: assertraises behaviour
Date Mon, 16 Jul 2012 15:55:18 +0200
References <CAF_E5JYANst57yOud+Ot0AbKkePruoCGPUNC5BbyBoMbgaw2_Q@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host smtp.semantics.de
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1
In-Reply-To <CAF_E5JYANst57yOud+Ot0AbKkePruoCGPUNC5BbyBoMbgaw2_Q@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2173.1342446935.4697.python-list@python.org> (permalink)
Lines 24
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1342446935 news.xs4all.nl 6903 [2001:888:2000:d::a6]:33265
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25416

Show key headers only | View raw


Am 16.07.2012 15:38, schrieb andrea crotti:
> This small example doesn't fail, but the OSError exception is cathed
> even if not declared..
> Is this the expected behaviour (from the doc I would say it's not).
> (Running on arch-linux 64 bits and Python 2.7.3, but it doesn the same
> with Python 3.2.3)
> 
> import unittest
> 
> class TestWithRaises(unittest.TestCase):
>     def test_ass(self):
>         with self.assertRaises(AssertionError):
>             assert False, "should happen"
>             raise OSError("should give error")

The OSError isn't catched as the code never reaches the line with "raise
OSError". In other words "raise OSError" is never executed as the
exception raised by "assert False" stops the context manager.

You should avoid testing more than one line of code in a with
self.assertRaises() block.

Christian

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: assertraises behaviour Christian Heimes <lists@cheimes.de> - 2012-07-16 15:55 +0200

csiph-web