Python import from parent directory

Don’t run the test from the tests folder. Run it from the root of your project, which is the module folder. You should very rarely need to muck with either sys.path or PYTHONPATH, and when you do, you’re either causing bugs for other libraries down the road or making life harder on your users.

python -m TestsFolder.UnitTest1

If you use a test runner like py.test, you can just run py.test from the root of your checkout and it’ll find the tests for you. (Assuming you name your tests something more like test_unit1.py. Your current naming scheme is a little unorthodox. ;))

Leave a Comment