I can\'t seem to get the nose testing framework to recognize modules beneath my test script in the file structure. I\'ve set up the simplest example that demonstrates the p
Just to complete the question: If you're struggling with structure like this:
project
├── m1
├ ├── __init__.py
├ ├── foo1.py
├ └──m2
├ ├── __init__.py
├ └── foo2.py
├
└── test
├── __init__.py
└── test.py
And maybe you want to run test from a path outside the project, include your project path inside your PYTHONPATH.
export PYTHONPATH=$PYTHONPATH:$HOME/path/to/project
paste it inside your .profile. If you're under a virtual environment, paste it inside the activate in your venv root
To those of you finding this question later on: I get the import error if I don't have an __init__.py
file in my tests directory.
My directory structure was like this:
./tests/
./test_some_random_stuff.py
If I ran nosetests:
nosetests -w tests
It would give the ImportError
that everyone else is seeing. If I add a blank __init__.py
file it works just fine:
./tests/
./__init__.py
./test_some_random_stuff.py
I just ran into one more thing that might cause this issue: naming of tests in the form testname.test.py
. That extra .
confounds nose and leads to it importing things it should not. I suppose it may be obvious that using unconventional test naming conventions will break things, but I thought it might be worth noting.