简体   繁体   English

python鼻子测试错误导入模块

[英]error importing module with python nosetest

I'm trying to test one class that imports another class that I've written, but I receive an error when I run nosetest. 我正在尝试测试一个导入了我编写的另一个类的类,但是运行鼻子测试时收到错误消息。

my package file structure is something like this: 我的包文件结构是这样的:

./__init__.py
./classA.py
./classB.py
./tests
    ./__init__.py
    ./testClassA.py

Where classA.py imports B like: 其中classA.py导入B如:

from classB import B

class A:
    def __init__(self):
       self.b=B() 
       ...

When I run nosetest, testClassA.py the tries to import A, it throws an error message. 当我运行鼻子测试,testClassA.py尝试导入A时,会引发错误消息。

testClassA.py has an import statement like this: testClassA.py具有如下的导入语句:

from ..classA import A

and the error message I receive is like this: 我收到的错误消息是这样的:

ImportError: no module named 'classB'

You might prefer using imports with the complete package inner path in the modules inside your package, like this: 您可能更喜欢在包内部模块中使用带有完整包内部路径的导入,如下所示:

from mypackage.classA import A

only inconvenience is if you have lots of imports and then later change your mind about the package name, you'll have to replace it in every file. 唯一的不便之处是,如果您有很多导入,然后又改变了对软件包名称的看法,则必须在每个文件中替换它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM