[Python-Dev] PEP: Consolidating names and classes in the `unittest` module

Terry Reedy tjreedy at udel.edu
Tue Jul 15 18:40:41 CEST 2008



Benjamin Peterson wrote:
> On Mon, Jul 14, 2008 at 6:18 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
>> "Benjamin Peterson" <musiccomposition at gmail.com> writes:
>>
>>> On Mon, Jul 14, 2008 at 8:25 AM, Ben Finney <ben+python at benfinney.id.au> wrote:
>>>> Use new-style classes throughout
>>>> --------------------------------
>>>>
>>>> The following classes will inherit explicitly from the built-in
>>>> `object` type, to make all classes in the module part of the new-style
>>>> type hierarchy.
>>>>
>>>> * ``TestResult``
>>>> * ``TestCase``
>>>> * ``TestSuite``
>>>> * ``TestLoader``
>>>> * ``_WritelnDecorator``
>>>> * ``TextTestRunner``
>>>> * ``TestProgram``
>>> They already do. __metaclass__ = type is found in unittest.py.
>> Not in the copy I have. Is that in 3.x only, or in 2.x also?
> 
> Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
> [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import unittest
>>>> isinstance(unittest.TestCase, object)
> True

*Everything* is an instance of object.
The question is whether the test classes are subclasses of object.
In particular, issubclass(unittest.TestCase, object)?
Either direct inheritance from object or '__metaclass__ = type' will 
make them so.  With neither, they will not be.

tjr



More information about the Python-Dev mailing list