项目文件夹中的__init__.py破坏了鼻子测试 [英] __init__.py in project folder breaks nose tests

查看:72
本文介绍了项目文件夹中的__init__.py破坏了鼻子测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

项目树:

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

bar.py:

def dumb_true():
    return True

测试/test_bar.py:

import bar

def test_bar_true():
        assert bar.dumb_true()

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

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?

我已经通过鼻子文档/手册页以及整个Internet广泛阅读了该主题.但是这一切如何解决却使我感到困惑!

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!

推荐答案

好像您的问题已得到回答

Looks like your question was answered here.

您的顶级目录中有一个__init__.py.这使它成为 包裹.如果将其删除,您的鼻子测试应该可以工作.

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

如果不删除它,则必须将导入更改为导入 dir.foo,其中dir是目录的名称.

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.

这篇关于项目文件夹中的__init__.py破坏了鼻子测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆