classification
Title: doctest problem with decorated function when decorator is defined in separate file
Type: behavior Stage: needs patch
Components: Library (Lib) Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: goetzpf
Priority: normal Keywords:

Created on 2009-09-03 14:53 by goetzpf, last changed 2010-07-11 09:29 by BreamoreBoy.

Files
File name Uploaded Description Edit
mytest.sh goetzpf, 2009-09-03 14:53 simple shell script creating 2 python files that demonstrate the problem
Messages (1)
msg92212 - (view) Author: Goetz Pfeiffer (goetzpf) Date: 2009-09-03 14:53
As described in bug 1108, doctest skips tests on 
functions that have been decorated with a decorator that 
is defined in a separate file.

As described in bug 1108, the problem lies in 
file "doctest.py", there in class "DocTestFinder",
there in method "_from_module"

There at about line 857 the following code makes problems:

        elif inspect.isfunction(object):
            return module.__dict__ is object.func_globals

The "func_globals" property of the function is used to find out if
the function was defined in the current module. This is not true
for a decorated function where the decorator is defined in another
module. Maybe _from_module() should use inspect.getmodulename() or
the "__module__" property of the function instead. "__module__"
is set correctly when the decorator uses functools.wraps().

The func_globals property is read-only, so there is no chance fix this
at the decorator definition.
History
Date User Action Args
2010-07-11 09:29:31BreamoreBoysetstage: needs patch
versions: + Python 3.1, Python 2.7, Python 3.2, - Python 2.6
2009-09-03 14:53:54goetzpfcreate