import unittest
class A(unittest.TestCase):
def setUp(self):
print "Hi it's you",self._testMethodName
def test_one(self):
self.assertEqual(5,5)
def tearDown(self):
print "Bye it's you", self._testMethodName
class B(A,unittest.TestCase):
def setUp(self):
print "Hi it's me", self._testMethodName
def test_two(self):
self.assertNotEqual(5,5)
unittest.main()
出力:上記のコードでPythonのunittestの継承のsetUp
Hi it's you test_one
Bye it's you test_one
.Hi it's me test_one
Bye it's you test_one
.Hi it's me test_two
FBye it's you test_two
======================================================================
FAIL: test_two (__main__.B)
----------------------------------------------------------------------
Traceback (most recent call last):
File "try_test_generators.py", line 19, in test_two
self.assertNotEqual(5,5)
AssertionError: 5 == 5
----------------------------------------------------------------------
Ran 3 tests in 0.005s
FAILED (failures=1)
、test_one
test_one
setUp()
の使用しているが、派生クラスにクラスAのsetUp()
を使用してテストケースクラスBから派生したすべてのテストケースに対してAのsetUp()
を使用できる方法はありますか?
私はあなたのアプローチを試みました。 Aの 'setUp()'とBの 'setUp()'を呼び出しています。私はAの 'setUp()'だけを使用したいのです。 – wonder
BのsetUpをオーバーライドしないでください。 – hspandher
はい。ありがとうございました。 – wonder