0

I am having trouble and difficulties with Pilgrim's Dive into python 3 Unit Testing chapter. I've run the exact same code in romantest2.py. Exceptions are not being handled in the code provided on the examples. I have deduced the example on the book into a smaller snippet:

TestCase1.py

import unittest class ToRomanBadInput(unittest.TestCase): def test_too_large(self): '''to_roman should fail with large input''' self.assertRaises(roman2.OutOfRangeError,roman2.to_roman,4000) if __name__ == '__main__': unittest.main() 

the file roman2.py

class OutOfRangeError(ValueError): pass def to_roman(n): raise OutOfRangeError("Value n {0} is larger than 3999.".format(n)) 

I can't seem to move on this part. What happen is that I expect the test case to fail. But it didn't instead it shows:

.. ------------------------------------------------------------ Ran 2 tests in 0.000s OK 

I am using and running this code PyDev in Eclipse and the version of python is version 3.3.3

1 Answer 1

1

You are asserting that the to_roman() function raises an exception. That test succeeds, your function indeed raises the exception.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks I am so stunned. I am such an idiot. Of course it works! I complete misunderstood unit testing. Now I understand it! This could have saved me a lot of trouble before! Thanks a lot.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.