Issue 764504: doctest fails with TypeError (original) (raw)
#mymod.py:
class base(dict): myupdate = dict.update #FINE def myfunc(self): pass
class derive(base): myname = base.myfunc #FAILS
import doctest, mymod doctest.testmod(mymod)
$ python2.3b2 mymod.py Traceback (most recent call last): File "mymod.py", line 8, in ? import doctest, mymod File "/home/me/mymod.py", line 9, in ? doctest.testmod(mymod) File "/usr/local/lib/python2.3/doctest.py", line 1137, in testmod f, t = tester.rundict(m.dict, name, m) File "/usr/local/lib/python2.3/doctest.py", line 900, in rundict f2, t2 = self.runone(value, name + "." + thisname) File "/usr/local/lib/python2.3/doctest.py", line 1061, in runone return self.rundoc(target, name) File "/usr/local/lib/python2.3/doctest.py", line 820, in rundoc f2, t2 = self.run__test(d, name) File "/usr/local/lib/python2.3/doctest.py", line 929, in run__test raise TypeError("Tester.run__test__: values in " TypeError: Tester.run__test__: values in dict must be strings, functions or classes;
Does not appear to be specific to Python v2.3.
Thanks!
Mark
Logged In: YES user_id=80475
Tim, would you like me to fix this one by searching the unbound method or by skipping the unbound method?
Since classes are searched recursively, it may be reasonable to search the unbound method. However, imports are not searched, so there is a precedent for skipping it.
Logged In: YES user_id=31435
If it has to be fixed , the only principle I can conjure up is that redundant testing is a waste of time and surprising. On that ground, in the specific example I'd rather skip it, since if the thing had a doctest, it would be most natural to run it from base.myfunc.doc.
If you're feeling more ambitious, I recently slammed in some useful doctest extensions from Jim Fulton. As I know you've already discovered, there are some warts. The deepest wart isn't obvious: Jim's extensions use their own ways of finding doctests to run. It would be good if everthing used the same ways of finding doctests to run. This bug report shows that doctest's old ways don't always work. It's unknown in how many situations the new ways don't work, and/or deliver different results.