Python unit test: testcase class with own constructor fails in standard library -


this question has answer here:

i have plain vanilla unit test, works expected, long leave out constructor.

import sys import unittest  class instance_test(unittest.testcase):    def __init__(self):      super(instance_test, self).__init__()      self.attribute = "new"    def test_something(self):      pass    def test_other(self):      self.asserttrue(true)      pass    def setup(self):      pass    def teardown(self):      pass  def suite():   return unittest.makesuite(instance_test, "test")  def main():   runner = unittest.texttestrunner(sys.stdout)   runner.run(suite())  if __name__ == "__main__":    main() 

with constructor in place in backtrace:

   traceback (most recent call last):    file "f:\gt\check.py", line 31, in  main()    file "f:\gt\check.py", line 28, in main       runner.run(suite())    file "f:\gt\check.py", line 24, in suite     return unittest.makesuite(instance_test, "test")   file "c:\python34\lib\unittest\loader.py", line 374, in makesuite     testcaseclass)   file "c:\python34\lib\unittest\loader.py", line 70, in loadtestsfromtestcase     loaded_suite = self.suiteclass(map(testcaseclass, testcasenames))   file "c:\python34\lib\unittest\suite.py", line 24, in __init__     self.addtests(tests)   file "c:\python34\lib\unittest\suite.py", line 60, in addtests     test in tests:  typeerror: __init__() takes 1 positional argument 2 given 

what's wrong , how else have central attribute shared different test_xxx methods?

i use unittest.testcase's setup() , teardown() methods instead of init. same thing you're doing except use setup method.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -