[z3-five] Re: Functional doctests for Five

Tres Seaver tseaver at zope.com
Thu Sep 30 16:16:32 MEST 2004


Philipp von Weitershausen wrote:
> "Stefan H. Holek" wrote:
> 
> 
>>On 29.09.2004, at 17:45, Tres Seaver wrote:
>>
>>>Note that unless you convert them using the 
>>>"docstring-on-an-empty-method" spelling, you will be changing 
>>>semantics of the tests:  the "tell-a-story-in-a-text-file" model 
>>>deliberated does *not* isolate tests from one another.  This is my 
>>>major beef with doctests:  the "isolated" spelling doesn't have the 
>>>win that the "story" case does, but the "story" case doesn't (can't) 
>>>do as good a job of "test one thing only."
>>>
>>
>>Are you saying that doctests may "spill over" to subsequent tests?
> 
> 
> No. doctests have setUp() and tearDown() just like other tests. However, within 
> a doctest file, you test in a story, not in atomic tests, e.g.:
> 
>   Booleans represent two states, true and false. In Python, true is
>   represented by the `True` variable:
> 
>     >>> a = 3
>     >>> b = 5
>     >>> a < b
>     True
> 
>   Simlarly, false is represented by `False`:
> 
>     >>> b = 2
>     >>> a < b
>     False
> 
> As opposed to:
> 
> class BoolTest(TestCase):
> 
>   def setUp(self):
>       self.a = 3
>       self.b = 5
> 
>   def test_true(self):
>       self.assert_(self.a < self.b)
> 
>   def test_false(self):
>       self.assert_(self.b > self.a)
> 
> 
> 
>>/me senses disturbance in the force, reaches for light saber ....
> 
> 
> Keep the mouse in the house, no need to worry. :)

I *am* worried, because I don't buy the "story" case as "best practice" 
for unit testing (yes, I am aware that Jim disagrees with me).  I prefer 
*tiny* unit tests, which test exactly *one* set of initial conditions 
and the expected outcome.  E.g.:

   def test_setValue_default_args(self):

       object = self._makeOne()
       object.setValue()
       self.assertEqual(object.getValue(), 'default')

   def test_setValue_explicit_bar(self):

       object = self._makeOne()
       object.setValue('explicit')
       self.assertEqual(object.getValue(), 'explicit')

I do *not* think that tests of "mutators" should interact with one 
another, in particular;  the case gets even dodgier when module-level 
globals are in play (e.g., registries).

I *do* believe that the documentation value of the "story" is 
worthwhile;  what I *don't* believe is that the "story" does as good a 
job actually testing the underlying code.

Tres.
-- 
===============================================================
Tres Seaver                                tseaver at zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com



More information about the z3-five mailing list