我正在尝试向Python中的对象添加unittest属性
class Boy:
def run(self, args):
print("Hello")
class BoyTest(unittest.TestCase)
def test(self)
self.assertEqual('2' , '2')
def self_test():
suite = unittest.TestSuite()
loader = unittest.TestLoader()
suite.addTest(loader.loadTestsFromTestCase(Boy.BoyTest))
return suite
但是,每当我调用self_test()
时,我总是得到"AttributeError: class Boy has no attribute 'BoyTest'"
。为什么?在
正如亚历克斯所说,你试图用“男孩测试”作为“男孩”的装束:
注意变化:
^{pr2}$收件人:
这能解决你的问题吗?在
作为
loadTestsFromTestCase
的参数,您试图访问Boy.BoyTest
,即类对象Boy
的BoyTest
属性,正如错误消息告诉您的那样,该属性不存在。你为什么不直接用BoyTest
代替呢?在相关问题 更多 >
编程相关推荐