我目前有一个Pythonunittest测试用例,如下所示:from unittest import TestCase as UTestCaseimport inspect class BaseParentTaskTest(UTestCase): def test_case_one(self): class A(BaseParentTask): def run(self, a, b): pass instance = A() print inspect.getargspec(instance.run).args instance._validate() if instance.valid: self.fail("Failed to invalidate based on wrong argument count.") def test_case_two(self): class A(BaseParentTask): def run(self, a, b, c, d): pass instance = A() print inspect.getargspec(instance.run).args if instance.valid: self.fail("Failed to invalidate based on wrong argument kw names.")从我的测试看来,运行之后test_case_one,A该类将保留在内存中,并且A在test_case_two运行时不会被in覆盖。这会导致test_case_two失败。这可以从日志中看到。在中test_case_one,预期输出是(self, a, b),它是:(self, a, b)在中test_case_two,预期输出为(self, a, b, c, d):(self, a, b)但是,显然不是。为什么A实例方法退出后不立即删除该类?如何解决此问题以使我的测试通过?
添加回答
举报
0/150
提交
取消