diff -r 3b211ee66b82 Lib/doctest.py --- a/Lib/doctest.py Mon Feb 01 22:13:43 2016 +0000 +++ b/Lib/doctest.py Sun Jan 31 17:47:48 2016 -0800 @@ -1087,6 +1087,11 @@ if inspect.isframe(obj): obj = obj.f_code if inspect.iscode(obj): lineno = getattr(obj, 'co_firstlineno', None)-1 + if lineno is None and isinstance(obj, property) and \ + hasattr(obj.fget, "__code__"): + obj = obj.fget.__code__ + # no need to subtract 1 because of decorator line + lineno = getattr(obj, 'co_firstlineno', None) # Find the line number where the docstring starts. Assume # that it's the first line that begins with a quote mark. diff -r 3b211ee66b82 Lib/test/test_doctest.py --- a/Lib/test/test_doctest.py Mon Feb 01 22:13:43 2016 +0000 +++ b/Lib/test/test_doctest.py Sun Jan 31 17:47:48 2016 -0800 @@ -646,6 +646,24 @@ >>> test = doctest.DocTestFinder().find(f)[0] >>> [e.lineno for e in test.examples] [1, 9, 12] + + +Line numbers of properties +~~~~~~~~~~~~~~~~~~~~~~~~~~ +DocTestFinder finds the line numbers of each propery example + + >>> @property + ... def foo(x): + ... ''' + ... >>> 1/1 + ... 1 + ... >>> 41 + 1 + ... 42 + ... ''' + >>> test = doctest.DocTestFinder().find(foo, "foo")[0] + >>> [e.lineno for e in test.examples] + [1, 3] + """ if int.__doc__: # simple check for --without-doc-strings, skip if lacking