__init__.py in project folder breaks nose tests

限于喜欢 提交于 2019-12-07 04:50:30

问题


project tree:

.
|-- bar.py
`-- test
    |-- __init__.py
    `-- test_bar.py

bar.py:

def dumb_true():
    return True

tests/test_bar.py:

import bar

def test_bar_true():
        assert bar.dumb_true()

I can run nosetests from inside the project or its test directory. If I add an empty __init__.py to the project folder, however, I can no longer run nosetests from inside the test directory, which doesn't make any sense to me.

.
|-- bar.py
|-- __init__.py  <-- new, empty file, ruining everything
`-- test
    |-- __init__.py
    `-- test_bar.py

Can anyone explain to me what's going on here?

I've read extensively on this topic - through nose documentation/man pages and all over the internet; but it looks very confusing to me how this all resolves!


回答1:


Looks like your question was answered here.

You've got an __init__.py in your top level directory. That makes it a package. If you remove it, your nosetests should work.

If you don't remove it, you'll have to change your import to import dir.foo, where dir is the name of your directory.



来源:https://stackoverflow.com/questions/18169447/init-py-in-project-folder-breaks-nose-tests

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