Note that there are some explanatory texts on larger screens.

plurals
  1. PODeriving a class from TestCase throws two errors
    text
    copied!<p>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.</p> <p>In so doing, I received two strange errors. One, I cannot solve. Here is the unsolvable one:</p> <pre><code>AttributeError: 'TestDesktopRootController' object has no attribute '_testMethodName' </code></pre> <p>Here is my base class:</p> <pre><code>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) </code></pre> <p>And here is my derived class:</p> <pre><code>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/') </code></pre> <p>The other strange error is:</p> <pre><code>TypeError: __init__() takes exactly 1 argument (2 given) </code></pre> <p>The "solution" to that was to add the word "args" to my <code>__init__</code> function in the derived class. Is there any way to avoid that?</p> <p>Remember, I have two errors in this one.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload