I’ve been struggled about where to put test files in a python project for a long time. Ideally, I think it is succinct to create a folder called “test” with all test files in it. However, the test files nested in the test folder need to import modules from parent folder. It is troublesome to import Python module from parent directory as you can’t just use `import ../module`. Here are the two correct ways to put test files in the test folder nested in a Python project:
- don’t create __init__.py in the root directory. And use `nosetests` under the root directory: http://stackoverflow.com/questions/3073259/python-nose-import-error
- use a helper file to import parent directory to python path: http://stackoverflow.com/a/23386287/1758727