I am trying to check return type on __repr__ . This is not a string, but what is it? What's going on here?
import unittest class MyClass(unittest.TestCase): class Dog(object): def __init__(self, initial_name): self._name = initial_name def get_self(self): return self def __repr__(self): return "Dog named '" + self._name + "'" def runTest(self): fido = self.Dog("Fido") self.assertEqual("Dog named 'Fido'", fido.get_self())
Running this gives:
FAIL: runTest (__main__.MyClass) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/xxxxx/fido.py", line 15, in runTest self.assertEqual("Dog named 'Fido'", fido.get_self()) AssertionError: "Dog named 'Fido'" != Dog named 'Fido' ---------------------------------------------------------------------- Ran 1 test in 0.006s FAILED (failures=1)
How can I pass this test?
source share