문제
파이썬의 객체에 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
그러나 나는 계속 받고있다 "AttributeError: class Boy has no attribute 'BoyTest'"
내가 전화 할 때마다 self_test()
. 왜요?
해결책
논쟁으로 loadTestsFromTestCase
, 당신은 액세스하려고합니다 Boy.BoyTest
, 즉, BoyTest
클래스 객체의 속성 Boy
, 오류 MSG가 말하는 것처럼 존재하지 않습니다. 그냥 사용하지 않는 이유는 무엇입니까? BoyTest
대신 거기?
다른 팁
Alex가 말했듯이 Boytest를 소년의 attifice로 사용하려고합니다.
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(BoyTest))
return suite
변경 사항에 유의하십시오 :
suite.addTest(loader.loadTestsFromTestCase(Boy.BoyTest))
에게:
suite.addTest(loader.loadTestsFromTestCase(BoyTest))
이것이 당신의 문제를 해결합니까?
제휴하지 않습니다 StackOverflow