assertraises behaviour



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()
.



Relevant Pages

  • unittest assertRaises Problem
    ... a question re unittest and assertRaises. ... No matter what I raise, ... I am running Python ...
    (comp.lang.python)
  • Re: python function in pipe
    ... os.popen3 looks nice but this executes command not function. ... You can use assertRaises if an exception is raised ... As I understand it, he has a C function that uses stdout and stderr to report errors and he wants to call it from Python. ... Another way would be to change the C code, adding a FILE parameter and replacing every printfwith fprintf; ...
    (comp.lang.python)