You are getting the method, not calling it.
Try :
self.assertEquals(target.getSuccessful(), True) # With parenthesss
It's OK the first time because you get the attribute _successful
, which was correctly initialized with True
.
But when you call target.getSuccessful
it gives you the method object itself, where it seems like you want to actuall call that method.
Explanation
Here is an example of the same thing that happens when you print an object's method:
class Something(object):
def somefunction(arg1, arg2=False):
print("Hello SO!")
return 42
We have a class, with a method.
Now if we print it, but not calling it :
s = Something()
print(s.somefunction) # NO parentheses
>>> <bound method Something.somefunction of <__main__.Something object at 0x7fd27bb19110>>
We get the same output <bound method ... at 0x...>
as in your issue. This is just how the method is represented when printed itself.
Now if we print it and actually call it:
s = Something()
print(s.somefunction()) # WITH parentheses
>>>Hello SO!
>>>42
The method is called (it prints Hello SO!
), and its return is printed too (42
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…