I am mocking the path attribute of an object that is used for sorting. However, trying to sort objects fails:
def __lt__(self, other: RealObject) -> bool:
"""Sort based on path."""
> return self.path < other.path
E TypeError: '<' not supported between instances of 'MagicMock' and 'MagicMock'
So I tried extending MagicMock, but it still fails:
class MockPath(MagicMock):
def __init__(self, name: Optional[str] = None, *args, **kw) -> None:
super().__init__(*args, **kw)
self.name = name or str(random.randint(1, 10000))
def __lt__(self, other) -> bool:
return self.name < other.name
def __lt__(self, other: RealObject) -> bool:
"""Sort based on path."""
> return self.path < other.path
E TypeError: '<' not supported between instances of 'MockPath' and 'MockPath'
How can I allow the mocked objects to sort? It's not important what they sort to, I just don't want it to fail.