__项目文件夹中的init\uuy.py中断了鼻子测试

2024-05-23 15:45:47 发布

您现在位置:Python中文网/ 问答频道 /正文

项目树:

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

棒.py:

^{pr2}$

测试/测试_棒.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

有人能给我解释一下这是怎么回事吗?在

我已经阅读了大量关于这个主题的文章-通过nose文档/手册页和互联网上的所有内容;但是对于我来说,这一切是如何解决的,我觉得非常困惑!在


Tags: 项目pytestimport目录文件夹trueinit
1条回答
网友
1楼 · 发布于 2024-05-23 15:45:47

你的问题似乎得到了回答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.

相关问题 更多 >