nose-devs/nose — Issue #440: Error for doctest with no output and defined doctest-result-variable
Author: jpellerin
Created: 2011-12-14 16:11:42+00:00
State: open

What steps will reproduce the problem?

def func():
""" doctest with no output

>>> a = 10
"""

nosetests --with-doctest myfunc.py -s --doctest-result-variable=thing

Results in:

======================================================================
ERROR: Doctest: myfunc.func
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/nose-1.0.0-py2.6.egg/nose/plugins/doctests.py", line 397, in tearDown
delattr(__builtin__, self._result_var)
AttributeError: thing

This is latest clone from google code on OSX.

It seems reasonable to check if the variable is defined before removing it:

diff -r 43d9088a4553 nose/plugins/doctests.py
--- a/nose/plugins/doctests.py	Fri Aug 05 10:26:21 2011 -0500
+++ b/nose/plugins/doctests.py	Sun Aug 14 01:48:55 2011 -0700
@@ -392,7 +392,8 @@
super(DocTestCase, self).tearDown()
if self._result_var is not None:
sys.displayhook = self._old_displayhook
- delattr(builtin_mod, self._result_var)
+ if hasattr(builtin_mod, self._result_var):
+ delattr(builtin_mod, self._result_var)

class DocFileCase(doctest.DocFileCase):
@@ -425,4 +426,5 @@
super(DocFileCase, self).tearDown()
if self._result_var is not None:
sys.displayhook = self._old_displayhook
- delattr(builtin_mod, self._result_var)
+ if hasattr(builtin_mod, self._result_var):
+ delattr(builtin_mod, self._result_var)

Google Code Info:
Issue #: 445
Author: matthew....@gmail.com
Created On: 2011-08-14T08:50:37.000Z
Closed On: