assertraises behaviour

andrea crotti andrea.crotti.0 at gmail.com
Mon Jul 16 09:38:17 EDT 2012


I found that the behaviour of assertRaises used as a context manager a
bit surprising.

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")


if __name__ == '__main__':
    unittest.main()



More information about the Python-list mailing list