Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for WebSockets #20

Open
gsmafra opened this issue Mar 14, 2017 · 1 comment
Open

Support for WebSockets #20

gsmafra opened this issue Mar 14, 2017 · 1 comment

Comments

@gsmafra
Copy link

gsmafra commented Mar 14, 2017

Is there, even if unintentionally, support for testing a Tornado WebSocket server with pytest-tornado? If yes, how would you go to make a basic example, similar to the one shown for the HTTP server?

This is what I tried to do but it gets stuck waiting for the websocket_connect to yield something

import pytest
import tornado.websocket

class MainHandler(tornado.websocket.WebSocketHandler):

    def open(self):
        print('Websocket connection open')

    def on_message(self, message):
        self.write_message(message)
        print('Websocket message received: %s' % message)

    def on_close(self):
        print('Websocket connection closed')

application = tornado.web.Application([
    (r"/", MainHandler),
])

@pytest.fixture
def app():
    return application

@pytest.mark.gen_test
def test_hello_world(http_port):
    base_url = f"ws://localhost:{http_port}/"
    client = yield tornado.websocket.websocket_connect(base_url)
    client.write_message('message')
    response = yield client.read_message()
    assert response is not None
@naught101
Copy link

I'm also interested in this, but can't get it working due to #56, and I'm having trouble figuring out how to turn it into a non-gen-test test. Any ideas welcome.

Pytest updates also mean http_port has to change to http_server_port, I think.

Is the reason this test is not working perhaps because the app is created, but never actually started?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants