已解决:将__init__.py
添加到Test/
中,并将testcode.py
重命名为test_code.py
。要运行测试,请键入cd -> Zee
,然后输入pytest
。
结构:
|--Zee/
| |--Test/
| | |--__init__.py
| | |--test_code.py
| |--Codetotest/
| | |--code.py
在code.py中
class Foo():
some code...
在testcode.py文件中
from Codetotest.code import Foo
def test_foo():
assert ...
当我在命令行中进入Zee目录并运行pytest Test/testcode.py时,我遇到了“ModuleNotFoundError:No module named Zee”的错误。 我该如何解决?
我尝试通过添加Test/__init__.py文件使Test成为一个模块,如此处所建议的。但是无论从哪个目录运行都不行。
Pytest版本为5.3.4,导入自python 3.6。
我不理解的是,当我将__init__.py添加到Zee/目录中时,它会给我同样的错误。
__init__.py
放在Test/
中,将文件重命名为test_whatever
,这就是我一开始应该做的 #rtfm - mpowcodezee
中使用__init__.py
,而在tests
中则不需要。 - Jérômetests
中。仅仅在模块和子模块文件夹中是不够的。 - tim.rohrer