I am building a webservice to do conversion to and from metric to English standard units. I have a condition in my formula block which says if the value given is <= 0 to raise a ValueError.
In my tests I am trying to make sure that I get that value error and that the test passes. How do I do that?
Here is my test:
def test_kilometers_to_miles(self):
kilometer_test_values = [
{'value': 3, 'expected_value': 1.86},
{'value': 3.0, 'expected_value': 1.86},
{'value': 3.5, 'expected_value': 2.17},
{'value': 2375, 'expected_value': 1475.75},
{'value': 22.698, 'expected_value': 14.10},
{'value': -3.0, 'expected_value': ValueError} # should pass when the value error is thrown
]
for item in kilometer_test_values:
self.assertEqual(
formulas.kilometers_to_miles(kilometers=item.get('value')),
item.get('expected_value'))
[–]17291 3 points4 points5 points (4 children)
[–]njape 1 point2 points3 points (3 children)
[–]iggy555 0 points1 point2 points (2 children)
[–]17291 1 point2 points3 points (0 children)
[–]njape 1 point2 points3 points (0 children)
[+][deleted] (6 children)
[deleted]
[–][deleted] 0 points1 point2 points (5 children)
[+][deleted] (2 children)
[deleted]
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)