classification
Title: __init__ TypeError reverses expected vs received args
Type: Stage: resolved
Components: Versions: Python 2.7, Python 2.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: antlong, flox, mark.dickinson
Priority: normal Keywords:

Created on 2010-08-13 18:05 by antlong, last changed 2010-08-13 18:14 by mark.dickinson. This issue is now closed.

Messages (3)
msg113802 - (view) Author: Anthony Long (antlong) Date: 2010-08-13 18:05
import unittest
from selenium import selenium


class SetupSomething(unittest.TestCase):

    def setUp(self, URL):

        self.selenium = selenium("localhost", 4444, "*firefox", self.URL)
        

    def tearDown(self):
        pass


class TestSomething(SetupSomething):
    def __init__():
        print "bug."
    
    def setUp(self):
        self.URL = "http://google.com/"

    def tearDown(self):
        pass

    def test_tester(self):
        self.selenium.open('/')
        print "no"
        


unittest.main()

----
TypeError: '__init__() takes no arguments (2 given)'
msg113803 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-08-13 18:08
Definitely it does not look like a bug.

>>> import unittest
>>> help(unittest.TestCase)

...

 |  If it is necessary to override the __init__ method, the base class
 |  __init__ method must always be called. It is important that subclasses
 |  should not change the signature of their __init__ method, since instances
 |  of the classes are instantiated automatically by parts of the framework
 |  in order to be run.

...
msg113805 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-08-13 18:14
What flox said.

There's no reversal here:  you've defined an __init__ method that takes no arguments.  The unittest framework tries to instantiate a TestSomething instance by calling it with two arguments (one of which is self).  If you look at the source for the TestCase class you'll see:

    def __init__(self, methodName='runTest'):
        ...


Note that the message you're seeing applies to *your* __init__ method:  that method expects no arguments (because that's the way you defined it), but it's getting two (because the unittest test runner calls it that way).
History
Date User Action Args
2010-08-13 18:14:30mark.dickinsonsetnosy: + mark.dickinson
messages: + msg113805
2010-08-13 18:08:57floxsetstatus: open -> closed

nosy: + flox
messages: + msg113803

resolution: not a bug
stage: resolved
2010-08-13 18:05:28antlongcreate