unittest: which directory structure?

Torsten Bronger bronger at physik.rwth-aachen.de
Sat Apr 12 11:14:22 EDT 2008


Hallöchen!

I try to port my doctests to unittest.  I've found good turorials
about *writing* unit tests but not about organising the files.

What's the best way to arrange the test source files?  I made a
directory called "tests" on the same level as my package, with
(roughly) one test module per package module and wanted to call each
of them from my Makefile or from some sort of root test module.

However, I cannot easily import the to-be-tested module.  Currently,
I begin every test module with

    # append the local package path to sys.path
    import sys, os.path
    rootpath = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
    sys.path.append(rootpath)

in order to be able to import the source modules.  I surely have
missed something because this is only a workaround solution.  Thanks
for any hints!

Tschö,
Torsten.

-- 
Torsten Bronger, aquisgrana, europa vetus
                                      Jabber ID: bronger at jabber.org
               (See http://ime.webhop.org for further contact info.)



More information about the Python-list mailing list