[Tutor] Doctest, object references and the use of ellipses
Tim Peters
tim.peters at gmail.com
Sun Apr 2 01:12:04 CEST 2006
[Don Taylor]
> I am trying to use Doctest and am having trouble using the ellipsis
> feature when trying to match an object reference.
>
> Here is the code:
>
> def add_change_listener(self, listener):
> '''
>
> Returns list of listeners just for testing.
> >>> def mock_listener():
> ... pass
> >>> model = Model()
> >>> model.add_change_listener(mock_listener) #doctest: +ELLIPSIS
> [<function mock_listener at 0x...>]
>
> '''
>
> self.listeners.append(listener)
> return self.listeners
>
> This is what I get back:
>
> Trying:
> model.add_change_listener(mock_listener) #doctest: +ELLIPSIS
> Expecting:
> [<function mock_listener at 0x...>]
> **********************************************************************
> File "D:\ProgrammingProjects\MVCExperiments\src\mvcmodel.py", line 14,
> in __main__.Model.add_change_listener
> Failed example:
> model.add_change_listener(mock_listener) #doctest: +ELLIPSIS
> Expected:
> [<function mock_listener at 0x...>]
> Got:
> [<function mock_listener at 0x00AD9730>]
That "should work", provided there aren't differences in whitespace
that are invisible to us in this medium. For example, if, in your
source file, there's actually a (one or more) trailing space on your
line of expected output, then it would _not_ match the actual output.
Try adding +REPORT_NDIFF to your #doctest options; that will point out
all differences (including whitespace).
More information about the Tutor
mailing list