single-quoted string conversion to triple-quoted string
robin and jim
robinjim at earthlink.net
Sat Apr 6 10:45:54 EST 2002
Ahh very good!
One of my shortcomings as a Python programmer is failing to remember that
almost everything is accessible (e.g., the __doc__ attribute). I'm much too
pre-conditioned, from other languages, to view such things as off-limits.
Thanks!
"Emile van Sebille" <emile at fenx.com> wrote in message
news:yNCr8.179198$Yv2.61305 at rwcrnsc54...
> "robin and jim" <robinjim at earthlink.net> wrote in message
> news:%_Br8.20276$nt1.1661286 at newsread2.prod.itd.earthlink.net...
> >
> > Gee, I thought it would be obvious why I was asking such a question
> <wink>!
> >
> > As unit tests run, using the unittest module shipped with Python 2.2,
> the
> > default behavior is to display a one-line description of each test.
> The
> > default implementation displays the first line of the test method's
> > **docstring**, if available; otherwise the name of the test method
> (e.g.,
> > "test_my_regular_expression") is displayed.
>
> Yes. This comes from the __doc__ attribute of the method.
>
> >
> > Well, yours truly thought he would be clever and add some additional
> > information to this docstring as it became available at run time via
> the %
> > placeholder mechanism. Alas, the result is a single-quoted string
> that
> > unittest does not recognize as a docstring so it displays the test
> method's
> > name (e.g., "test_my_regular_expression") instead. I, naively, think
> that if
> > the single quoted result can be re-converted to a triple-quoted
> string, it
> > will be recognized by unittest.
> >
>
> You could change the __doc__ attribute of the method before testing:
>
> import unittest
>
> class IntegerArithmenticTestCase(unittest.TestCase):
> def testAdd(self): ## test method names begin 'test*'
> self.assertEquals((1 + 2), 3)
> self.assertEquals(0 + 1, 1)
> def testMultiply(self):
> self.assertEquals((0 * 10), 0)
> self.assertEquals((5 * 8), 40)
>
> if __name__ == '__main__':
> testvals = [3,7,4,5]
> IntegerArithmenticTestCase.__dict__['testAdd'].__doc__ = 'testing
> with %s' % testvals
> unittest.main()
>
> HTH,
>
> --
>
> Emile van Sebille
> emile at fenx.com
>
> ---------
>
>
More information about the Python-list
mailing list