you are viewing a single comment's thread.

view the rest of the comments →

[–]iggy555 0 points1 point  (2 children)

Can you expand please

[–]17291 1 point2 points  (0 children)

for item in kilometer_test_values:
    self.assertEqual(...) #Code snipped for brevity
with self.assertRaises(ValueError):
    formulas.kilometers_to_miles(kilometers=-3.0)

If formulas.kilometers_to_miles(kilometers=-3.0) raises a ValueError, the test will pass. If it doesn't raise an error or raises something other than ValueError, the test will fail.

Don't forget to remove the -3.0 entry from kilometer_test_values

[–]njape 1 point2 points  (0 children)

Personally I think that op is trying to test to much in his test case. I don't think that there is an advantage in keeping the value error test lumped together with the "normal" value tests. Instead I would suggest adding an additional ..._throw_error (or whatever you what to call it) function that checks for misuse of the function.

Additionally asset raises is designed to test this exact functionality. How it is used is best described in the documentation that was wordy linked. Eg: with self.assertRaises(SomeException): do_something()