Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6646553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:25:51+00:00 2026-05-26T00:25:51+00:00

I have some basic setup/teardown code that I want to reuse in a whole

  • 0

I have some basic setup/teardown code that I want to reuse in a whole bunch of unit tests. So I got the bright idea of creating some derived classes to avoid repeating code in every test class.

In so doing, I received two strange errors. One, I cannot solve. Here is the unsolvable one:

AttributeError: 'TestDesktopRootController' object has no attribute '_testMethodName'

Here is my base class:

import unittest
import twill
import cherrypy
from cherrypy._cpwsgi import CPWSGIApp


class BaseControllerTest(unittest.TestCase):

    def __init__(self):
        self.controller = None

    def setUp(self):
        app = cherrypy.Application(self.controller)

        wsgi = CPWSGIApp(app)

        twill.add_wsgi_intercept('localhost', 8080, lambda : wsgi)

    def tearDown(self):
        twill.remove_wsgi_intercept('localhost', 8080)

And here is my derived class:

import twill
from base_controller_test import BaseControllerTest

class TestMyController(BaseControllerTest):

    def __init__(self, args):
        self.controller = MyController()
        BaseControllerTest.__init__(self)

    def test_root(self):
        script = "find 'Contacts'"
        twill.execute_string(script, initial_url='http://localhost:8080/')

The other strange error is:

TypeError: __init__() takes exactly 1 argument (2 given)

The “solution” to that was to add the word “args” to my __init__ function in the derived class. Is there any way to avoid that?

Remember, I have two errors in this one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:25:51+00:00Added an answer on May 26, 2026 at 12:25 am

    It’s because you’re overriding __init__() incorrectly. Almost certainly, you don’t want to override __init__() at all; you should do everything in setUp(). I’ve been using unittest for >10 years and I don’t think I’ve ever overridden __init__().

    However, if you really do need to override __init__(), remember that you don’t control where your constructor is called — the framework calls it for you. So you have to provide a signature that it can call. From the source code (unittest/case.py), that signature is:

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

    The safe way to do this is to accept any arguments and just pass ’em up to the base class. Here is a working implementation:

    class BaseTest(unittest.TestCase):
        def __init__(self, *args, **kwargs):
            unittest.TestCase.__init__(self, *args, **kwargs)
    
        def setUp(self):
            print "Base.setUp()"
    
        def tearDown(self):
            print "Base.tearDown()"
    
    
    class TestSomething(BaseTest):
        def __init__(self, *args, **kwargs):
            BaseTest.__init__(self, *args, **kwargs)
            self.controller = object()
    
        def test_silly(self):
            self.assertTrue(1+1 == 2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have setup some basic code that triggers on focus of various input fields:
Hi have some forms that I want to use some basic php validation (regular
I have some basic questions around understanding fundamentals of Performance testing. I know that
I have some basic PHP code: $raceramps56[short] = My Test Product; $leftMenu = '<div
Currently, I have some basic code to play a simple tone whenever a button
I'm using the Drupal Quiz module, and have setup some basic quizzes and stuff
I have some pretty basic HTML/CSS that isn't working as I expect. Basically I
I have a CI application that uses .htaccess for URL routing. My basic setup
We have some code that must access low level windows XP os calls which
I have some code that is structured as follows from my.modules import MyClass Class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.