bobber6467 / python-nose

Automatically exported from code.google.com/p/python-nose
0 stars 0 forks source link

Error for doctest with no output and defined doctest-result-variable #445

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

<myfunc.py>
def func():
    """ doctest with no output

    >>> a = 10
    """
</myfunc.py>

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)

Original issue reported on code.google.com by matthew....@gmail.com on 14 Aug 2011 at 8:50

GoogleCodeExporter commented 8 years ago
Still an issue in "nosetests version 1.1.2" , Ubuntu 12.04 LTS. Was this fixed 
in mainline?

Original comment by andres.riancho@gmail.com on 13 Jun 2012 at 6:06