当我使用unittest.main()运行以下测试用例时:
import unittest
class TestInner_Helper(unittest.TestCase):
class InnerClass(object):
def __init__(self):
self.flag_var = False
def setFlag(self, newVal):
self.flag_var = newVal
def test_inner_class(self):
inner = InnerClass()
self.assertFalse(inner.flag_var)
inner.setFlag(True)
self.assertTrue(inner.flag_var)
if __name__ == "__main__":
unittest.main()
我收到以下错误:
Traceback (most recent call last):
File "test_inner_class.py", line 13, in test_inner_class
inner = InnerClass()
NameError: global name 'InnerClass' is not defined
为什么测试运行器无法实例化内部类?我在OSX上的Python 2.7.14上运行它。