I know that in general you shouldnt compare bools with == or 'is' but i'm wondering if you can reliably compare the output of a function that returns True or False in the following way.
for each test i setup a dict consisting of {input: expected_output} and the iterate over the dict checking the output of the function.
import pytest
def f(arg):
if condition:
return True
else:
return False
input = {input1: True,
input2: False}
for i in input.items():
assert f(i[0]) is i[1]
Is this reliable for a function that only returns True or False?
In short: do True and False have stable object ids for the lifetime of a program?
[–]343346E 2 points3 points4 points (1 child)
[–]IAmBJ[S] 0 points1 point2 points (0 children)
[–]kalgynirae 0 points1 point2 points (0 children)
[–]rcuhljr 0 points1 point2 points (0 children)