diff -r 586195685aaf Lib/doctest.py --- a/Lib/doctest.py Tue Aug 18 14:30:15 2015 -0400 +++ b/Lib/doctest.py Mon Aug 24 12:15:06 2015 -0400 @@ -1099,6 +1099,25 @@ if pat.match(source_lines[lineno]): return lineno + if isinstance(obj, str) and source_lines is not None: + # This will find __test__ string doctests if and only if they are + # formatted as triple quoted strings in the source. + lines = obj.splitlines(keepends=True) + index = 1 # skip first line in case it directly follows the """ + while index < len(lines) and not lines[index].strip(): + index += 1 + if index < len(lines): + lineno = 0 + while lineno < len(source_lines): + if lines[index] == source_lines[lineno]: + print('match') + for i in range(index+1, len(lines)-1): + if lines[i] != source_lines[lineno+i-index]: + break + else: + return lineno-index + lineno += 1 + # We couldn't find the line number. return None