subclassing from unittest

Terry Jan Reedy tjreedy at udel.edu
Wed May 22 17:29:23 EDT 2013


On 5/22/2013 11:32 AM, Charles Smith wrote:

Have you red this? I will suggest some specifics.
http://www.catb.org/esr/faqs/smart-questions.html

> I'd like to subclass from unittest.TestCase.

What version of Python.

 > I observed something interesting and wonder if anyone can explain 
what's going on... some
> subclasses create  null tests.
>
> I can create this subclass and the test works:

What does 'works' mean?

>    class StdTestCase (unittest.TestCase):
>        blahblah

I bet that this (and the rest of your 'code' is not what you actually 
ran. Unless blahblah is bound (to what?), this fails with NameError.
Give us what you ran so we can run it too, and modify it.

> and I can create this subsubclass and the test works:
>
>    class aaaTestCase (StdTestCase):
>        moreblahblah
>
> but if I create this subsubclass (or any where the first letter is
> capital):
>
>    class AaaTestCase (StdTestCase):
>        differentblahblah
>
> the test completes immediately without any work being done.

What does this mean? I see no difference with the following

import unittest
class StdTestCase (unittest.TestCase): pass
class lowerSub(StdTestCase): pass
class UpperSub(StdTestCase): pass

unittest.main(verbosity=2, exit=False)

# prints (3.3)
----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

Same as before the subclasses were added.

--
Terry Jan Reedy





More information about the Python-list mailing list