Title: doctest problem with decorated function when decorator is defined in separate file
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
Status: closed Resolution: duplicate
Dependencies: Superseder: Problem with doctest and decorated functions
View: 1108
Assigned To: Nosy List: bruno.dupuis, ezio.melotti, goetzpf, michael.foord
Priority: normal Keywords:

Created on 2009-09-03 14:53 by goetzpf, last changed 2018-12-12 06:46 by serhiy.storchaka. This issue is now closed.

File name Uploaded Description Edit goetzpf, 2009-09-03 14:53 simple shell script creating 2 python files that demonstrate the problem bruno.dupuis, 2012-11-30 11:59 updated the test to 2.X and 3.X
Messages (3)
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 "", 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.
msg176682 - (view) Author: Bruno Dupuis (bruno.dupuis) Date: 2012-11-30 11:59
updated the test to 3k (requires sh and Python2.{6,7} as python2). It works. Anyone to close?
msg176683 - (view) Author: Bruno Dupuis (bruno.dupuis) Date: 2012-11-30 12:01
it's a duplicate of #1108
Date User Action Args
2018-12-12 06:46:50serhiy.storchakasetstatus: open -> closed
superseder: Problem with doctest and decorated functions
resolution: duplicate
stage: needs patch -> resolved
2012-11-30 12:01:13bruno.dupuissetmessages: + msg176683
2012-11-30 11:59:21bruno.dupuissetfiles: +
nosy: + ezio.melotti, michael.foord
messages: + msg176682

2012-11-29 17:03:20bruno.dupuissetnosy: + bruno.dupuis
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