Python unit tests

Neilen Marais nmarais at snowisp.com
Wed Apr 6 09:51:26 UTC 2005


Hi!

I'm trying to do unit testing as I develop some python apps that support
the fortran code I mentioned before. The way I assumed it should work,
is to use one of the python test classes, then to import my .py file,
and do some tests etc.  But I can't seem to figure out where to put my
python source, I always get: 

qmtest.exception  exceptions.ImportError: No module named outfilecomp

I have a test database in a directory ...../tests. I put my .py file
there, which seems to be the CWD when QMTest is running python tests.
Then I use (in this instance) a python.ExecTest. My test code looks
something like this:

import outfilecomp

testvar = outfilecomp.blah(5)

where blah is just a short circuit testing function that returns its
argument, and the python expression is:

testvar == 5

Am I missing something obvious? Where should I put my .py file, or where
can I specify the load path? It seems like a bad idea to hardcode it
into my tests. To me the obvious solution seems to be to specify this in
a context variable. But how do I get to access the context variable
short of A) writing my own test class or B) accessing it as environment
variables inside the test code.

A) is unattractive, since I've never written a QMTest class, and it
seems like something that should have been solved already ;)
B) is unattractive, since that would clutter every test case with code
to read environment variables. Not a lot of code, but still unnecesary
repetition.

If I'm approaching this wrong, please hit me with a clue-stick. BTW, I'm
using version 2.2 from Debian Sarge, which seems to be the newest
version.

Thanks
Neilen




More information about the qmtest mailing list