[TIP] nose2 backwards compatibility questions

Kumar McMillan kumar.mcmillan at gmail.com
Wed Aug 11 09:08:51 PDT 2010


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'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



More information about the testing-in-python mailing list