Skip to content Skip to sidebar Skip to footer

Assertionerror: Zerodivisionerror Not Raised By Fun

I have a function called division. After an exception is raised in the try block, it's getting caught by except block, so I am getting an AssertionError while testing the except bl

Solution 1:

The function in question is NON TESTABLE.

It neither returns a value nor changes some object.

The only thing it will return is an exception which is other than 'ZeroDivisionError', which is not possible for the function logic.

So it is not possible to test the function without changing the function code itself and making it 'TESTABLE'.

Solution 2:

Because the function catch the ZeroDivisionError. When a / b raised the ZeroDivisionError, the code will print ez and return None.Remove the 'except ZeroDivisionError' and the test will pass.

Post a Comment for "Assertionerror: Zerodivisionerror Not Raised By Fun"