Why does 'raised Error' work, but 'assert' doesn't?

80 views Asked by At

There is a difference when I use assert and raised ValuError, why?

The following code, only stop my script when I use raise ValueError, assert does not work.

assert (len(dictA) != len(dictB)), 'Your have an .... error'

if len(dictA) != len(dictB):
    raise ValueError('Your have an ... error')
1

There are 1 answers

2
Filipe Aleixo On

You need to use

assert (len(dictA) == len(dictB))

The error is thrown when the condition evaluates to False.