[Python-Dev] test_descrtut failing
Guido van Rossum
guido@python.org
Sat, 08 Sep 2001 23:06:15 -0400
> > You said that when you run the test standalone the type names are
> > different. *How* do you run it standalone? If I run it like this:
> >
> > ./python Lib/test/test_descrtut.py
> >
> > it works fine (and -v works here too). But if I run it like this:
> >
> > ./python
> > >>> import test.test_descrtut # this does not run the tests!
> > >>> test.test_descrtut.test_main() # this does!
>
> Indeed, I run it the second way (no command line on the Mac,
> remember:-).
>
> The fun thing is that if I run it completely standalone (by dragging
> test_descrtut.py to the interpreter, the test can handle this
> situation) it works fine! So, there must be something wrong with
> either the test framework (or maybe this re-import trick?) that
> doesn't work as expected on the Mac.
To find out, try this:
>>> import sys
>>> sys.argv = ['regrtest.py', '-v', 'test_decrtut']
>>> import test.regrtest # this does not run any tests
>>> test.regrtest.main()
This should run just the one test, under regrtest, in verbose mode, so
without regrtest comparing and interpreting the output of doctest.
> Maybe test_regrtest can be thought which tests use unittest or
> doctest, and not try to be helpful in those cases?
That's up to Tim; sounds like a good idea to me but requires that
regrtest knows which tests use doctest.
> For now I've just put a note in the readme file for MacPython that
> this test is expected to fail, but I'd like to fix it eventually, of
> course.
Of course.
> I have another gripe with the new unittest stuff (this is the first
> time I've seen the doctest thing, never knew it was there!), and
> that's that most of the test failures are difficult to
> interpret. Whereas the old-style tests simply "print math.sin(math.pi)"
> and tell you they expected the output to be 0 but got -1 in stead the
> unittest-based tests often don't give that information.
> Most of the unittest-based tests use only failUnless/assert_ in stead
> of the higher-level functions, i.e. test_time uses things like
> self.assert_(time.ctime(self.t)
> == time.asctime(time.localtime(self.t)))
> where the test results would be a lot easier to interpret if they used
> self.assertEqual(time.ctime(self.t),
> time.asctime(time.localtime(self.t)),
> "ctime(T) != asctime(localtime(T)")
Absolutely! Doctest is actually better in this respect (when not
thwarted by regrtest) because it does this automatically, but we
should definitely try to use self.assertEqual(x, y) rather than
self.assert(x == y)! (If you find any examples, please fix them or at
least report them.
--Guido van Rossum (home page: http://www.python.org/~guido/)