Skip to content

Instantly share code, notes, and snippets.

@pconerly
Created May 12, 2014 17:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pconerly/e07ba1294266b38c6a5a to your computer and use it in GitHub Desktop.
Save pconerly/e07ba1294266b38c6a5a to your computer and use it in GitHub Desktop.
Failing to run Tornado tests
#!/usr/bin/env python
import tornado.httpserver
import tornado.ioloop
import tornado.web
from tornado.options import options
class FooHandler(tornado.web.RequestHandler):
def get(self):
self.write("derp")
url_patterns = [
(r"/foo", FooHandler),
]
class DebugApp(tornado.web.Application):
def __init__(self):
tornado.web.Application.__init__(self, url_patterns, debug=True, xsrf_cookies=False)
def main():
app = DebugApp()
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(6006)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
main()
(smokesignal)peterconerly$ python runtest.py
Debug app 0.1.0
-------------- Running Test Suite --------------
<unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[]>, <unittest.suite.TestSuite tests=[]>, <unittest.suite.TestSuite tests=[<test.TestDebug testMethod=test_foo>]>]>]>
(<type 'exceptions.TypeError'>, TypeError('__init__() takes exactly 1 argument (2 given)',), <traceback object at 0x1055c9488>)
[' File "/Users/peterconerly/.virtualenvs/smokesignal/lib/python2.7/site-packages/tornado/stack_context.py", line 302, in wrapped\n ret = fn(*args, **kwargs)\n', ' File "/Users/peterconerly/.virtualenvs/smokesignal/lib/python2.7/site-packages/tornado/httpserver.py", line 328, in _on_headers\n self.request_callback(self._request)\n']
E
======================================================================
ERROR: test_foo (test.TestDebug)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/peterconerly/code/tornado_debug/test.py", line 13, in test_foo
response = self.fetch('/foo')
File "/Users/peterconerly/.virtualenvs/smokesignal/lib/python2.7/site-packages/tornado/testing.py", line 333, in fetch
return self.wait()
File "/Users/peterconerly/.virtualenvs/smokesignal/lib/python2.7/site-packages/tornado/testing.py", line 272, in wait
self.__rethrow()
File "/Users/peterconerly/.virtualenvs/smokesignal/lib/python2.7/site-packages/tornado/testing.py", line 208, in __rethrow
raise_exc_info(failure)
File "/Users/peterconerly/.virtualenvs/smokesignal/lib/python2.7/site-packages/tornado/stack_context.py", line 302, in wrapped
ret = fn(*args, **kwargs)
File "/Users/peterconerly/.virtualenvs/smokesignal/lib/python2.7/site-packages/tornado/httpserver.py", line 328, in _on_headers
self.request_callback(self._request)
TypeError: __init__() takes exactly 1 argument (2 given)
----------------------------------------------------------------------
Ran 1 test in 0.011s
FAILED (errors=1)
[E 140512 10:36:30 testing:614] FAIL
(smokesignal)peterconerly$
# pip freeze for my virtualenv
backports.ssl-match-hostname==3.4.0.2
gnureadline==6.3.3
hiredis==0.1.3
ipdb==0.8
ipython==2.0.0
nose==1.3.3
redis==2.9.1
rom==0.26.1
six==1.6.1
tornado==3.2.1
wsgiref==0.1.2
#!/usr/bin/env python
import unittest
from os import path
import sys
import tornado.testing
PROJECT_PATH = path.dirname(path.abspath(__file__))
sys.path.append(PROJECT_PATH)
def all():
suite = unittest.defaultTestLoader.discover('./', 'tests.py', path.dirname(path.abspath(__file__)))
print suite
return suite
if __name__ == '__main__':
# Print a nice message so that we can differentiate between test runs
print ''
print '%s %s' % ('Debug app', '0.1.0')
print '\033[92m' + '-------------- Running Test Suite --------------' + '\033[0m'
print ''
tornado.testing.main()
from tornado.httpclient import AsyncHTTPClient
import tornado.testing
from tornado.testing import AsyncTestCase, AsyncHTTPTestCase
from app import DebugApp
class TestDebug(AsyncHTTPTestCase):
def get_app(self):
return DebugApp
def test_foo(self):
response = self.fetch('/foo')
print response
assert response == 'foo'
def runTest(self):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment