organizing python code with tests

eliben eliben at
Fri Aug 15 08:04:53 CEST 2008


At the moment, I place all the code of my project in a src/ directory,
and all the tests in a sibling tests/ directory, so for instance a
sample project can look like this:


While this works fine, I have a couple of questions:

1) To make this scheme work, each test file begins with
sys.path.insert(0, '../src'). I wonder if there's a better way to do
this, because this one doesn't look flexible (what if the code gets
complex and I subdivide it to directories in src/...)

2) Is there a better way to organize this ? Preferably I'm looking for
a single method that is applicable to:
  * Complete stand-alone applications with a single entry-point
  * Libraries with several files that should be imported by the users

Perhaps this is too much to ask, but hope dies last :-)

Thanks in advance

More information about the Python-list mailing list