I am just trying to execute one simple testcase list below,
# testinheritence.py
import unittest
class heleClass(object):
def execute_test_plan(self, test_plan):
self.assertEqual("a", "a")
class TestParent(heleClass):
def testName(self):
test_plan = {"a": 1}
self.execute_test_plan(test_plan)
class SqlInheritance(unittest.TestCase, TestParent):
print ("get into inheritance")
if __name__ == "__main__":
unittest.main()
And then test it with this command: "nosetests3 -s testinheritence.py" but I encounter these exception persistently, it complains,
======================================================================
ERROR: testinheritence.TestParent.execute_test_plan
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/nose/case.py", line 198, in runTest
self.test(*self.arg)
TypeError: execute_test_plan() missing 1 required positional argument: 'test_plan'
======================================================================
ERROR: testinheritence.TestParent.testName
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/nose/case.py", line 198, in runTest
self.test(*self.arg)
File "/home/dave/scripts/testinheritence.py", line 16, in testName
self.execute_test_plan(test_plan)
File "/home/dave/scripts/testinheritence.py", line 10, in execute_test_plan
self.assertEqual("a", "a")
AttributeError: 'TestParent' object has no attribute 'assertEqual'
----------------------------------------------------------------------
Ran 4 tests in 0.003s
Run it with "python -m unittest testinheritence", the testcase will pass successfully, I googled this but haven't got an approache to fix it, is there anything i missed here? any response is highly apprecaited!
You have several issues here. Your heleClass
is not a proper unittest class (you used object
as your parent. As result it has no self.assertEqual()
method. Furthermore, nose thinks that "execute_test_plan" is a test, and calls it as part of test, and it fails, because it needs an argument. Try marking execute_test_plan
as @nottest
:
import unittest
from nose.tools import nottest
class heleClass(unittest.TestCase):
@nottest
def execute_test_plan(self, test_plan):
self.assertEqual("a", "a")
class TestParent(heleClass):
def testName(self):
test_plan = {"a": 1}
self.execute_test_plan(test_plan)
if __name__ == "__main__":
unittest.main()