Code Management

Sergio Correia sergio.correia at
Wed Nov 21 02:02:58 CET 2007

Let's see:

> 1) Should I put my unittests in a subdirectory? Does the subdirectory
> have to be a package?

Sure, to avoid cluttering put the tests in a folder called 'tests'
(and any input the tests require, like mock files, output files used
to test if the output is correct, etc etc, should be put in that
folder or in a subfolder of 'tests'.

I like this setup:

../ package1
 ../../ tests
../../../ mock_files

and so on

If you want to be able to import the tests from python (say, 'from
myproject.tests import test_all'), then yes, you need to make the
tests folder a subpackage (just drop an empty file)

> 2) Does the main folder /myproject have to be a package? Should I put
> my modules directly under /myproject, or should I create a subfolder,
> for example /myproject/modules

Of course... make /myproject a package. Now, if your modules are kinda
small you can just dump them in /myproject, but if what you are doing
is fairly complex, it's better to move each module to its own folder.

> Does anyone have any "best practices" as to how to manage your code?

I want 'best practices' too... anyone?


PS: Casey, neat idea with the ''. Btw, I think relative
imports can be helpful:

More information about the Python-list mailing list