title: Unit testing Bottle app with WebTest
body: <p>I've been attempting to familiarize myself with unit testing but have been having a lot of trouble with it. I have a bottle app that I tried using Unittest, which didn't seem appropriate, so now I'm trying WebTest.</p>
  
  <p>The trouble is that I can't get it to even remotely work, even following along with the most basic/superficial example on the site.</p>
  
  <p>Here's the example:</p>
  
  <pre><code>from webtest import TestApp
  import mywebapp
  
  def test_functional_login_logout():
      app = TestApp(mywebapp.app)
  
      app.post('/login', {'user': 'foo', 'pass': 'bar'}) # log in and get a cookie
  
      assert app.get('/admin').status == '200 OK'        # fetch a page successfully
  
      app.get('/logout')                                 # log out
      app.reset()                                        # drop the cookie
  
      # fetch the same page, unsuccessfully
      assert app.get('/admin').status == '401 Unauthorized'
  </code></pre>
  
  <p>my code:</p>
  
  <pre><code>@get('/')
  def page():
      letters = scorer.get_letter_set()
      c = db_connect()
      c.execute('SELECT player_name,score FROM Scores order by score DESC limit 5')
      data = c.fetchall()
      c.close()
  
      return template('board', letters=letters, scores=data, letterset=json.dumps(letters))
  </code></pre>
  
  <p>Then, in the console (one problem is that I can't seem to get any testing code to work from a file. If I run any file in my project directory, bottle runs the development server instead. Any attempt to run test files results in import errors.)</p>
  
  <pre><code>&gt;&gt;&gt; from webtest import TestApp
  &gt;&gt;&gt; import board
  &gt;&gt;&gt; app = TestApp(board.page)
  &gt;&gt;&gt; res = app.get('/')
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/webtest/app.py", line 322, in get
      expect_errors=expect_errors)
    File "/usr/local/lib/python2.7/dist-packages/webtest/app.py", line 605, in do_request
      res = req.get_response(app, catch_exc_info=True)
    File "/usr/local/lib/python2.7/dist-packages/webob/request.py", line 1313, in send
      application, catch_exc_info=True)
    File "/usr/local/lib/python2.7/dist-packages/webob/request.py", line 1281, in call_application
      app_iter = application(self.environ, start_response)
    File "/usr/local/lib/python2.7/dist-packages/webtest/lint.py", line 198, in lint_app
      iterator = application(environ, start_response_wrapper)
  TypeError: page() takes no arguments (2 given)
  </code></pre>