Unittest fails to import module

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sat Jun 29 15:26:56 EDT 2013


On Sat, 29 Jun 2013 19:13:47 +0000, Martin Schöön wrote:

> $PYTHONPATH points at both the code and the test directories.
> 
> When I run blablabla_test.py it fails to import blablabla.py

What error message do you get?

 
> I have messed around for oven an hour and get nowhere. I have done
> unittesting like this with success in the past and I have revisited one
> of those projects and it still works there.
[...]
> Any leads?

The first step is to confirm that your path is setup correctly. At the 
very top of blablabla_test, put this code:

import os, sys
print(os.getenv('PYTHONPATH'))
print(sys.path)


What do they say? What should they say?


The second step is to confirm that you can import the blablabla.py 
module. From the command line, cd into the code directory and start up a 
Python interactive session, then run "import blablabla" and see what it 
does.


-- 
Steven



More information about the Python-list mailing list