Specially named directories using nosetests

拟墨画扇 提交于 2019-12-06 07:59:47
alecxe

Quick solution is to remove __init__.py from the top level directory. Another option is to use relative imports, for your example: replace import a.b with from ...a import b.

The culprit of this mess and trickiness is nose importer.

If the directory you are running nosetests in, is a package, nose won't add it to sys.path, otherwise, it'll add it (source). Then, it goes up throw directory tree and applies recursively the same logic. Same thing for all affected files. This explains why it isn't working with __init__.py - root dir (src2 in your case) wasn't in sys.path - that's why package a wasn't found.

But, the open question here is: why it worked the first time, with src folder? src folder is on sys.path in this case. May be there will be other answers or edits.

See related questions:

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