[Fixed]-Django finds tests but fail to import them

26👍

Yeah… there’s a problem with running ./manage.py, in that it adds the current directory to the PYTHONPATH.

This problem happens when you put an __init__.py inside the root folder.

One solution would be, in this case, to never use manage.py, but only django-admin.py <commands> --settings=inkasso.inkasso.settings – of course, this assumes either that when running this command, you’re one level up, outside your root folder inkasso, or you have your main package installed in site-packages.

For example, if the complete path to your settings.py file is /home/user/projects/inkasso/inkasso/settings.py, you need to be in /home/user/projects when running this command.

If however you’ve got your package installed inside your site-packages, the above restriction changes: you can be anywhere except /home/user/projects/inkasso or any of its subfolders or so on.

Another solution is to edit your manage.py file to add this line:

if __name__ =='__main__': #line already present
    #this will make the python interpreter see your packages as inkasso.inkasso.whatever
    os.chdir('..')  # <<<---This is what you want to add

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mvod.dev_settings")
    ....

Leave a comment