Socketio chat, testing with pytest #1751
Replies: 2 comments 13 replies
-
I think you just have a small bug in your logic: result = ''
@sio.on('bot_uttered')
def on_message(data):
nonlocal result # <--- you have to declare result, so that the global variable is used
print('bot answered:', data)
result = data |
Beta Was this translation helpful? Give feedback.
-
BTW, i have absolutely working solution of client, which is fits to my pytest tests
BUT, ideally i would like to avoid using global variables. As i understand i can't pass any variable right into the handler to save data in it, because events emitted on server side, which i don't have access to (and don't need because of tests logic) and any handlers do take only one argument - @miguelgrinberg Are there any workarounds to save data returned from server and avoid using global variables? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey all !
Could you guys help or explain how to get data from event handler and manipulate it. My goal is to set up testing of Chatbot on socket.io using pytest.
So i've created the client in
conftest.py
In my tests i do call message as a client
test.py
But, where i'm stuck is, i can't do any assertions with response of bot which came to
data
inbot_uttered
event handler, since it's not available under my test.I did try to save this data to local variable, but somewhy it's not getting saved
result
stays emptysame way when i do
return data
result is empty
Tests output
Any suggestions?
Beta Was this translation helpful? Give feedback.
All reactions