实际上我没有看到我在这里做错了什么,但我想这是一个非常简单和基本的问题:
模块1名为Widget17_Sorter.py:
class Widget17_Sorter(object):
def get_data_from_database(self, database_name, user, password, host ):
...do stuff here...
模块2名为Test_Widget17_Sorter.py(实际上是单元测试)
import Widget17_Sorter
class Test(unittest.TestCase):
...do some other stuff here...
def test_get_data_from_database(self):
sorter = Widget17_Sorter.Widget17_Sorter()
raw_data = sorter.get_data_from_database( self.database_name,
self.user, self.password, self.host )
执行测试时,我收到以下错误消息:
ERROR: test_get_data_from_database (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "TestWidget17_Sorter.py", line 50, in test_get_data_from_database
raw_data = sorter.get_data_from_database( self.database_name,
AttributeError: 'Widget17_Sorter' object has no attribute 'get_data_from_database'
为什么?
答案 0 :(得分:0)
尝试以这种方式导入:
from Widget17_Sorter import Widget17_Sorter
...
my_widget = Widget17_Sorter(...)
my_widget.get_data_from_database(...)
...并将两个脚本放在同一个文件夹中......