5

项目树:

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

酒吧.py:

def dumb_true():
    return True

测试/test_bar.py:

import bar

def test_bar_true():
        assert bar.dumb_true()

我可以nosetests从项目内部或其测试目录中运行。但是,如果我在项目文件夹中添加一个空__init__.py文件夹,我将无法再nosetests从测试目录中运行,这对我来说没有任何意义。

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

谁能向我解释这里发生了什么?

我已经广泛阅读了这个主题——通过鼻子文档/手册页和整个互联网;但我觉得这一切是如何解决的很令人困惑!

4

1 回答 1

3

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.

于 2014-01-28T19:40:06.007 回答