Re: assertraises behaviour

2012-07-17 Thread Andrea Crotti
To clarify my "problem", I just thought that assertRaises if used as context manager should behave as following: - keep going if the exception declared is raised - re-raise an error even if catched after the declared exception was catched I was also confused by the doc a bit: "Test that an excep

RE: assertraises behaviour

2012-07-17 Thread Prasad, Ramit
> On 17/07/2012 18:49, Prasad, Ramit wrote: > >>> import unittest > >>> > >>> class TestWithRaises(unittest.TestCase): > >>> def test_first(self): > >>> assert False > >>> > >>> def test_second(self): > >>> print("also called") > >>> assert True > >>> > >>>

Re: assertraises behaviour

2012-07-17 Thread Terry Reedy
On 7/17/2012 5:06 AM, andrea crotti wrote: Well this is what I meant: import unittest class TestWithRaises(unittest.TestCase): def test_first(self): assert False def test_second(self): print("also called") assert True if __name__ == '__main__': unitt

Re: assertraises behaviour

2012-07-17 Thread Mark Lawrence
On 17/07/2012 18:49, Prasad, Ramit wrote: import unittest class TestWithRaises(unittest.TestCase): def test_first(self): assert False def test_second(self): print("also called") assert True if __name__ == '__main__': unittest.main() in this case

RE: assertraises behaviour

2012-07-17 Thread Prasad, Ramit
> > import unittest > > > > class TestWithRaises(unittest.TestCase): > > def test_first(self): > > assert False > > > > def test_second(self): > > print("also called") > > assert True > > > > if __name__ == '__main__': > > unittest.main() > > > > in this ca

Re: assertraises behaviour

2012-07-17 Thread Ulrich Eckhardt
Am 17.07.2012 11:06, schrieb andrea crotti: import unittest class TestWithRaises(unittest.TestCase): def test_first(self): assert False def test_second(self): print("also called") assert True if __name__ == '__main__': unittest.main() in this case als

Re: assertraises behaviour

2012-07-17 Thread andrea crotti
2012/7/16 Peter Otten <__pete...@web.de>: > No, I don't see how the code you gave above can fail with an OSError. > > Can you give an example that produces the desired behaviour with nose? Maybe > we can help you translate it to basic unittest. > > -- > http://mail.python.org/mailman/listinfo/pytho

Re: assertraises behaviour

2012-07-16 Thread Peter Otten
andrea crotti wrote: > Good thanks, but there is something that implements this behaviour.. > For example nose runs all the tests, and if there are failures it goes > on and shows the failed tests only in the end, so I think it is > possible to achieve somehow, is that correct? No, I don't see ho

Re: assertraises behaviour

2012-07-16 Thread andrea crotti
Good thanks, but there is something that implements this behaviour.. For example nose runs all the tests, and if there are failures it goes on and shows the failed tests only in the end, so I think it is possible to achieve somehow, is that correct? -- http://mail.python.org/mailman/listinfo/pytho

Re: assertraises behaviour

2012-07-16 Thread Peter Otten
andrea crotti wrote: > 2012/7/16 Christian Heimes : >> >> 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 mo

Re: assertraises behaviour

2012-07-16 Thread andrea crotti
2012/7/16 Christian Heimes : > > 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

Re: assertraises behaviour

2012-07-16 Thread Christian Heimes
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.

assertraises behaviour

2012-07-16 Thread andrea crotti
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, bu