現在、次のような Pythonunittest
テスト ケースがあります。
from unittest import TestCase as UTestCase
import 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
です。test_case_two
故障の原因となります。
これは、ログから確認できます。ではtest_case_one
、予想される出力は(self, a, b)
であり、次のとおりです。
(self, a, b)
ではtest_case_two
、予想される出力は(self, a, b, c, d)
次のとおりです。
(self, a, b)
しかし、そうではないことは明らかです。
A
インスタンスメソッドが終了してもすぐにクラスが消去されないのはなぜですか? これを修正してテストに合格するにはどうすればよいですか?