[TIP] Test discovery for unittest

Olemis Lang olemis at gmail.com
Fri Apr 10 11:36:15 PDT 2009


On Fri, Apr 10, 2009 at 1:35 PM, Scott David Daniels
<Scott.Daniels at acm.org> wrote:
> Olemis Lang wrote:
>>
>> On Fri, Apr 10, 2009 at 1:18 PM, Scott David Daniels wrote:
>>
>>>
>>> Olemis Lang wrote:> class PackageTestLoader(unittest.TestLoader):
>>>
>>>>
>>>>   ...
>>>>   def __init__(self, pattern=defaultPattern, loader=defaultTestLoader,
>>>>                impall=False, globs={}, ns={},
>>>>                ):
>>>>       ...
>>>>       self.locals = ns
>>>>       self.globs = globs
>>>>       ...
>>>>
>>>
>>> I'd suggest instead:
>>>  def __init__(self, pattern=defaultPattern, loader=defaultTestLoader,
>>>              impall=False, globs=None, ns=None):
>>>     if ns is None:
>>>         ns = {}
>>>     if globs is None:
>>>         globs = {}
>>>     ...
>>>     self.locals = ns
>>>     self.globs = globs
>>>     ...
>>>
>>
>> Please ... why ?
>
> Because default mutable args can be a disaster.  Although it is unlikely
> that two instance of PackageTestLoader will be created, if you ever do,
> and they are both created without specifying locals and globals, they will
> share the same set of globals and locals, and the second one will start with
> a bunch of things loaded that you'll never expect.  This can make tests that
> should fail on NameErrors pass.
>

+ 100 ^ 2 ... you 'r right

This will be ready for the next week ... I'll try to implement
something more and prepare a new version ...

Thnx a lot !

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:
Se retira el BDFL ... ¿El fin de Python 3k?  -
http://feedproxy.google.com/~r/simelo-es/~3/HpncxTKfB1c/se-retira-el-bdfl-el-fin-de-python-3k_02.html



More information about the testing-in-python mailing list