【发布时间】:2015-12-05 01:06:03
【问题描述】:
我正在努力获得正确的 python 导入。我想要实现的是拥有一个包含多个源文件的模块和一个包含单元测试的测试文件夹。
无论我做什么,我都无法让 py.test-3 执行我的测试。我的目录布局如下:
.
├── module
│ ├── __init__.py
│ └── testclass.py
└── tests
└── test_testclass.py
__init__.py 文件如下所示:
__all__ = ['testclass']
testclass.py 文件如下所示:
class TestClass(object):
def __init__(self):
self.id = 1
我的单元测试是这样的:
import pytest
from module import TestClass
def test_test_class():
tc = TestClass()
assert(tc.id==1)
无论我如何调用 py.test-3,我最终都会得到:
E ImportError: No module named 'module'
【问题讨论】:
标签: python unit-testing python-3.x pytest