[Tutor] import and unittest
Alan Gauld
alan.gauld at btinternet.com
Tue Jan 16 11:06:37 CET 2007
"Thomas Coopman" <thomas.coopman at gmail.com> wrote
.
> I wondered if it was possible to do something like this:
>
> src/
> -a_module/
> -sub_module/
> test/
> -a_module/
> -sub_module/
>
I don;t see any reason why not although its slightly more work.
Personally I tend to keep the tests with the code, but thats
mainly because tools such as editors tend to remember the last
folder opened and its a pain navigating between the two folders.
The other system I have used(in C++ not Python) is to have
a test folder inside each src folder like:
src/
mod1/
f1.py
test/
testf1.py
mod2/
f2.py
f3.py
test/
testf1.py
testf2.py
etc.
This minimises navigation and keeps the tests separate.
Its also relatively easy to filter out the tests when it comes
time to package upp the code for distribution (assuming
you want to lose them!)
> I have something like this but I don't know how to organize the
> imports in
> the tests and I don't know if this is a good idea. What do you
> think?
I think in Python you should create a package structure for
your code so that import can find the modules more easily.
But I've never tried this in Python, my Python projects are rarely
big enough to warrant it.
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list