(Reported by a community member over email.)
The Testing Assertions exercise in the Defentsive Programming episode includes one assert statement that does not work as described:
assert int(value) will not raise an AssertionError but instead a ValueError when value cannot be converted to an integer.
The exercise should be updated to account for this. I suggest two possible approaches:
- update the solution to mention that a ValueError will be raised, and ideally explaining why the
assert statement is never evaluated.
- update the exercise example to remove that line.
I know that the idea of replacing assertions with try...except has been the topic of multiple discussions, and @DamienIrving was working on a PR to switch the approach taken in the episode (unfortunately disrupted by the lesson infrastructure transition). I mention this because the appearance of a ValueError rather than an AssertionError from the code in this exercise seems to be a case where try...except could be less confusing for the Learner.
(Reported by a community member over email.)
The Testing Assertions exercise in the Defentsive Programming episode includes one
assertstatement that does not work as described:assert int(value)will not raise anAssertionErrorbut instead aValueErrorwhenvaluecannot be converted to an integer.The exercise should be updated to account for this. I suggest two possible approaches:
assertstatement is never evaluated.I know that the idea of replacing assertions with
try...excepthas been the topic of multiple discussions, and @DamienIrving was working on a PR to switch the approach taken in the episode (unfortunately disrupted by the lesson infrastructure transition). I mention this because the appearance of aValueErrorrather than anAssertionErrorfrom the code in this exercise seems to be a case wheretry...exceptcould be less confusing for the Learner.