Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a pytest method similar to in assertIsNone(x) of unittest

Tags:

python

pytest

I want to check for None value in pytest code. Is there a similar assertIsNone(x) method? I have tried the following but looking for a better way.

assert x == None, "Sucess"
assert x != None, " Failure"
like image 352
Dave Avatar asked Mar 03 '23 23:03

Dave


1 Answers

You can use the following - if you'd like to check that the object is actually None type:

assert x is None, "asserion failure message here"
assert x is not None, "assertion failure message here"

On another note; in order for you to fully understand the difference between is and equal to - ==; here's a tiny example:

0 == False
# True - Equality since 0 is considered a false value.
0 is False
# False - Since they don't share the same identity.

Simple overview:

The == operator compares by checking for equality.

The is operator, however, compares identities.

like image 81
Julian Camilleri Avatar answered Apr 28 '23 02:04

Julian Camilleri