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


Groups > comp.lang.python > #25416 > unrolled thread

Re: assertraises behaviour

Started byChristian Heimes <lists@cheimes.de>
First post2012-07-16 15:55 +0200
Last post2012-07-16 15:55 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#25416 — Re: assertraises behaviour

FromChristian Heimes <lists@cheimes.de>
Date2012-07-16 15:55 +0200
SubjectRe: assertraises behaviour
Message-ID<mailman.2173.1342446935.4697.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web