缺少必需的位置参数 - nosetests

问题描述:

我只是试图执行下面一个简单的测试用例列表,缺少必需的位置参数 - nosetests

# 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() 

然后用这个命令来测试它:“nosetests3 -s testinheritence.py”但我坚持遇到这些异常,它抱怨,

====================================================================== 
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 

与“蟒蛇-m单元测试testinheritence”来运行它,测试用例会顺利通过,我GOOGLE了这一点,但还没收到approache修复它,有什么我错过了吗?任何回应都非常受欢迎!

这里有几个问题。你的heleClass不是一个合适的单元测试类(你使用object作为你的父类,因此它没有self.assertEqual()方法。此外,nose认为“execute_test_plan”是一个测试,并将其称为测试的一部分,并且它失败了,因为它需要一个自变量尝试标记execute_test_plan@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() 
+0

感谢解决我的问题完全,谢谢! – jungler