Unittest fails to import module
Roy Smith
roy at panix.com
Sat Jun 29 15:25:10 EDT 2013
In article <b38pvbFjlv9U1 at mid.individual.net>,
Martin Schöön <martin.schoon at gmail.com> wrote:
> I know the answer to this must be trivial but I am stuck...
>
> I am starting on a not too complex Python project. Right now the
> project file structure contains three subdirectories and two
> files with Python code:
>
> code
> blablabla.py
> test
> blablabla_test.py
> doc
> (empty for now)
>
> blablabla_test.py contains "import unittest" and "import blablabla"
>
> $PYTHONPATH points at both the code and the test directories.
A couple of generic debugging suggestions. First, are you SURE the path
is set to what you think? In your unit test, do:
import sys
print sys.path
and make sure it's what you expect it to be.
> When I run blablabla_test.py it fails to import blablabla.py
Get unittest out of the picture. Run an interactive python and type
"import blablabla" at it. What happens?
One trick I like is to strace (aka truss, dtrace, etc on various
operating systems) the python process and watch all the open() system
calls. See what paths it attempts to open when searching for blablabla.
Sometimes that gives you insight into what's going wrong.
> I have messed around for oven an hour and get nowhere.
What temperature was the oven set at?
More information about the Python-list
mailing list