[TIP] nose2 backwards compatibility questions

Michael Foord fuzzyman at voidspace.org.uk
Wed Aug 11 09:14:25 PDT 2010


On 11/08/2010 17:08, Kumar McMillan wrote:
> On Wed, Aug 11, 2010 at 9:54 AM, Michael Foord
> <fuzzyman at voidspace.org.uk>  wrote:
>    
>>> Sounds good. nose's pattern is to actually start discovery in those
>>> directories, if they are present, to ensure that if the project layout
>>> is something like:
>>>
>>> lib/mod.py
>>> tests/tests.py
>>>
>>> that mod is importable from tests.
>>>
>>>        
>> Ok, that sounds straightforward. One question - if there is a lib/ directory
>> *and* a src/ directory do you add both to the path and continue discovery
>> into both of them - or just the first that you find?
>>
>> In some ways allowing both is easier. :-)
>>      
> I'd rather see the developer take responsibility for putting lib and
> src dirs on their sys.path.

It isn't just a question of adding directories to sys.path - test 
discovery has to happen in these directories using the right directory 
as the "top level" of the project for turning paths into importable names.

The question is also one of supporting common project layouts "out of 
the box", so making it controllable is one thing and the default 
behaviour is another...

(I'm a big fan of tox by the way - unittest2 itself is tested with tox.)

Michael

> It's as simple as this (in Nose):
>
> class MyTestLayout(Plugin):
>      ...
>      def begin(self):
>          sys.path.extend(['lib','src'])
>
> nose.main(addplugins=[MyTestLayout()], ...)
>
>
> Furthermore, I think something like tox [1] encourages a much better
> practice whereby before any tests are run your module(s) under test
> are installed just like they would be in real life.  You also can
> specify any external modules to install that are specific to your test
> suite (and not your production code).
>
> [1] http://codespeak.net/tox/
>
> -Kumar
>    


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.





More information about the testing-in-python mailing list