assertraises behaviour

andrea crotti andrea.crotti.0 at
Mon Jul 16 16:37:38 CEST 2012

2012/7/16 Christian Heimes <lists at>:
> 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
> --

Ok now it's more clear, and normally I only test one thing in the block.
But I find this quite counter-intuitive, because in the block I want
to be able to run something that raises the exception I catch (and
which I'm aware of), but if another exception is raised it *should*
show it and fail in my opinion..

More information about the Python-list mailing list