diff -r 2863470caebb Lib/doctest.py --- a/Lib/doctest.py Sun Dec 18 02:56:18 2011 +0100 +++ b/Lib/doctest.py Sun Dec 18 16:04:48 2011 +0100 @@ -2252,6 +2252,16 @@ def id(self): return self._dt_test.name + def __eq__(self, other): + if type(self) is not type(other): + return NotImplemented + + return hash(self) == hash(other) + + def __hash__(self): + return hash((type(self), self._dt_test, self._dt_optionflags, + self._dt_setUp, self._dt_tearDown, self._dt_checker)) + def __repr__(self): name = self._dt_test.name.split('.') return "%s (%s)" % (name[-1], '.'.join(name[:-1])) diff -r 2863470caebb Lib/test/test_doctest.py --- a/Lib/test/test_doctest.py Sun Dec 18 02:56:18 2011 +0100 +++ b/Lib/test/test_doctest.py Sun Dec 18 16:04:48 2011 +0100 @@ -347,6 +347,19 @@ Traceback (most recent call last): ValueError: line 2 of the docstring for some_test lacks blank after ...: '...print 1' +Compare `DocTest`: + + >>> test == test + True + >>> docstring = ''' + ... >>> print 42 + ... 42 + ... ''' + >>> test2 = parser.get_doctest(docstring, globs, 'other_test', + ... 'other_file', 10) + >>> test == test2 + False + """ def test_DocTestFinder(): r"""