PYTHON: nosetests import file path with multiple modules/files

≡放荡痞女 提交于 2019-12-08 16:43:34

Everything needs to be with respect to your execution point. You are running your nose command from the root of ex48, therefore all your imports need to be with respect to that location.

Therefore, in game.py you should be importing with respect to ex48. Therefore:

from ex48.otherpy import House

The same logic should be applied to your example referencing the temp folder.

from ex48.temp import temp

The only solution I have found is to post the following to the top of the main file:

try: 
     # This handles imports when running .py files from inside app directory
     from file_to_import.py import class_instance
except:
     # This handles imports when running nosetests from top-level (above app) 
     # directory
     from directory_containing_app_files.file_to_import import class_instance

I am supremely interested in an alternative solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!