Code Management

Sergio Correia sergio.correia at gmail.com
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:

myproject
../ package1
 ../../ tests
../../../ mock_files
../package2

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 __init__.py 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?

Sergio


PS: Casey, neat idea with the 'alltests.py'. Btw, I think relative
imports can be helpful:
http://www.python.org/dev/peps/pep-0328/#guido-s-decision



More information about the Python-list mailing list