Python __项目文件夹中的init__u;.py会中断鼻测试
项目树:Python __项目文件夹中的init__u;.py会中断鼻测试,python,testing,packages,nose,Python,Testing,Packages,Nose,项目树: . |-- bar.py `-- test |-- __init__.py `-- test_bar.py def dumb_true(): return True import bar def test_bar_true(): assert bar.dumb_true() bar.py: . |-- bar.py `-- test |-- __init__.py `-- test_bar.py def dumb_tru
.
|-- bar.py
`-- test
|-- __init__.py
`-- test_bar.py
def dumb_true():
return True
import bar
def test_bar_true():
assert bar.dumb_true()
bar.py:
.
|-- bar.py
`-- test
|-- __init__.py
`-- test_bar.py
def dumb_true():
return True
import bar
def test_bar_true():
assert bar.dumb_true()
测试/test\u bar.py:
.
|-- bar.py
`-- test
|-- __init__.py
`-- test_bar.py
def dumb_true():
return True
import bar
def test_bar_true():
assert bar.dumb_true()
我可以从项目或其测试目录中运行nosetests
。但是,如果我在项目文件夹中添加一个空的\uuuu init\uuuuu.py
,我将无法再从测试目录中运行nosetests
,这对我来说没有任何意义
.
|-- bar.py
|-- __init__.py <-- new, empty file, ruining everything
`-- test
|-- __init__.py
`-- test_bar.py
。
|--巴比
|--__init__u;.py看起来您的问题已经得到了回答
您的顶级目录中有一个\uuuu init\uuu.py
。这使它成为一个
包裹如果你把它取下来,你的鼻子测试应该会起作用
如果不删除它,则必须将导入更改为导入
dir.foo,其中dir是目录的名称
你用什么命令跑鼻子?此外,使用绝对进口可能更有帮助。如果bar.py所在的目录也命名为bar?是的,我知道绝对导入,但我不喜欢叶子知道它们所在的分支的名称。我正在开发,所以名称有点流动,所以这些东西所在文件夹的名称不可靠。我只是在运行相当多的stocknosetests
调用。在python社区中,绝对导入比相对导入更被接受为标准实践。是否向测试添加参数以指定测试的路径?如果是,您要指定什么路径?