[Checkins] SVN: manuel/trunk/ fix a bug that caused all doctests to fail if sys.argv contained the string "-v"

Benji York cvs-admin at zope.org
Thu Jan 24 03:40:03 UTC 2013


Log message for revision 129100:
  fix a bug that caused all doctests to fail if sys.argv contained the string "-v"

Changed:
  U   manuel/trunk/CHANGES.txt
  U   manuel/trunk/src/manuel/bugs.txt
  U   manuel/trunk/src/manuel/doctest.py

-=-
Modified: manuel/trunk/CHANGES.txt
===================================================================
--- manuel/trunk/CHANGES.txt	2013-01-24 02:43:12 UTC (rev 129099)
+++ manuel/trunk/CHANGES.txt	2013-01-24 03:40:01 UTC (rev 129100)
@@ -1,6 +1,12 @@
 CHANGES
 =======
 
+1.6.1 (2013-01-24)
+------------------
+
+- Fixed a bug that made doctests fail if sys.argv contained the string "-v".
+
+
 1.6.0 (2012-04-16)
 ------------------
 

Modified: manuel/trunk/src/manuel/bugs.txt
===================================================================
--- manuel/trunk/src/manuel/bugs.txt	2013-01-24 02:43:12 UTC (rev 129099)
+++ manuel/trunk/src/manuel/bugs.txt	2013-01-24 03:40:01 UTC (rev 129100)
@@ -180,6 +180,7 @@
     >>> m3.debug
     True
 
+
 TestCase id methods
 -------------------
 
@@ -194,3 +195,44 @@
     >>> m = manuel.Manuel()
     >>> six.print_(TestCase(m, manuel.RegionContainer(), None).id())
     <memory>
+
+
+DocTestRunner peaks at sys.argv
+-------------------------------
+
+A (bad) feature of DocTestRunner (and its subclass DebugRunner) is that it
+will turn on "verbose" mode if sys.argv contains "-v".  This means that if you
+pass -v to a test runner that then invokes Manuel, all tests would fail
+because extra junk was inserted into the doctest output.  That is, before I
+fixed it.  Now, manuel.doctest.Manuel passes "verbose = False" to the
+DocTestRunner constructor which disables the functionality.
+
+We can ensure that the verbose mode is always disabled by creating test
+standins for DocTestRunner and DebugRunner that capture their constructor
+arguments.
+
+.. code-block:: python
+
+    import doctest
+    import manuel.doctest
+    class FauxDocTestRunner(object):
+        def __init__(self, **kws):
+           self.kws = kws
+    try:
+        manuel.doctest.DocTestRunner = FauxDocTestRunner
+        manuel.doctest.DebugRunner = FauxDocTestRunner
+
+        m = manuel.doctest.Manuel()
+
+    finally:
+        manuel.doctest.DocTestRunner = doctest.DocTestRunner
+        manuel.doctest.DebugRunner = doctest.DebugRunner
+
+Now, with the Manuel object instantiated we can verify that verbose is off for
+both test runners.
+
+    >>> m.runner.kws['verbose']
+    False
+
+    >>> m.debug_runner.kws['verbose']
+    False

Modified: manuel/trunk/src/manuel/doctest.py
===================================================================
--- manuel/trunk/src/manuel/doctest.py	2013-01-24 02:43:12 UTC (rev 129099)
+++ manuel/trunk/src/manuel/doctest.py	2013-01-24 03:40:01 UTC (rev 129100)
@@ -4,7 +4,10 @@
 
 doctest = manuel.absolute_import('doctest')
 
+DocTestRunner = doctest.DocTestRunner
+DebugRunner = doctest.DebugRunner
 
+
 class DocTestResult(six.StringIO):
     pass
 
@@ -96,9 +99,9 @@
 class Manuel(manuel.Manuel):
 
     def __init__(self, optionflags=0, checker=None, parser=None):
-        self.runner = doctest.DocTestRunner(optionflags=optionflags,
-            checker=checker)
-        self.debug_runner = doctest.DebugRunner(optionflags=optionflags)
+        self.runner = DocTestRunner(optionflags=optionflags,
+            checker=checker, verbose=False)
+        self.debug_runner = DebugRunner(optionflags=optionflags, verbose=False)
         def evaluate_closure(region, document, globs):
             # capture "self"
             evaluate(self, region, document, globs)



More information about the checkins mailing list