Hello we are trying to create some frontend tests for webapps we want to run locally and when runing the test we encounter WebSocketHandler error
Below is code and the error message.
Is this related to using MagicMock ?
Thank you.
from streamlit.testing.v1 import AppTest
import unittest
import os
class TestClass(unittest.TestCase):
def test_stack_assumptions(self):
at=AppTest.from_file("../../webapps/stack_assumptions/pages/Home.py").run()
assert not at.exception
File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/webapps/stack_assumptions/pages/Home.py", line 25, in <module>
Session_ID, UUID, UsersName, Session_Start, Session_State, Active_User, ActiveUsersName, Session_End, UserDict = current_session_state()
File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/webapps/stack_assumptions/Function_Lib/Home_funcs.py", line 32, in current_session_state
headers = _get_websocket_headers()
File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/.venv/lib/python3.10/site-packages/streamlit/runtime/metrics_util.py", line 397, in wrapped_func
result = non_optional_func(*args, **kwargs)
File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/.venv/lib/python3.10/site-packages/streamlit/web/server/websocket_headers.py", line 43, in _get_websocket_headers
raise RuntimeError(
RuntimeError: SessionClient is not a BrowserWebSocketHandler! (<MagicMock name='mock.get_client()' id='4766645264'>)
tests/tests_streamlit/test_stack_assumptions.py:6 (TestClass.test_stack_assumptions)
self = <test_stack_assumptions.TestClass testMethod=test_stack_assumptions>
def test_stack_assumptions(self):
at=AppTest.from_file("../../webapps/stack_assumptions/pages/Home.py").run()
> assert not at.exception
E assert not ElementList(_list=[Exception(message="SessionClient is not a BrowserWebSocketHandler! (<MagicMock name='mock.get_client()' id='4766645264'>)", stack_trace=['File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/.venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 600, in _run_script\n exec(code, module.__dict__)', 'File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/webapps/stack_assumptions/pages/Home.py", line 25, in <module>\n Session_ID, UUID, UsersName, Session_Start, Session_State, Active_User, ActiveUsersName, Session_End, UserDict = current_session_state()', 'File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/webapps/stack_assumptions/Function_Lib/Home_funcs.py", line 32, in current_session_state\n headers = _get_websocket_headers()', 'File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/.venv/lib/python3.10/site-packages/streamlit/runtime/metrics_util.py", line 397, in wrapped_func\n result = non_optional_func(*args, **kwargs)', 'File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/.venv/lib/python3.10/site-packages/streamlit/web/server/websocket_headers.py", line 43, in _get_websocket_headers\n raise RuntimeError('])])
E + where ElementList(_list=[Exception(message="SessionClient is not a BrowserWebSocketHandler! (<MagicMock name='mock.get_client()' id='4766645264'>)", stack_trace=['File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/.venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 600, in _run_script\n exec(code, module.__dict__)', 'File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/webapps/stack_assumptions/pages/Home.py", line 25, in <module>\n Session_ID, UUID, UsersName, Session_Start, Session_State, Active_User, ActiveUsersName, Session_End, UserDict = current_session_state()', 'File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/webapps/stack_assumptions/Function_Lib/Home_funcs.py", line 32, in current_session_state\n headers = _get_websocket_headers()', 'File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/.venv/lib/python3.10/site-packages/streamlit/runtime/metrics_util.py", line 397, in wrapped_func\n result = non_optional_func(*args, **kwargs)', 'File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/.venv/lib/python3.10/site-packages/streamlit/web/server/websocket_headers.py", line 43, in _get_websocket_headers\n raise RuntimeError('])]) = AppTest(\n _script_path='../../webapps/stack_assumptions/pages/Home.py',\n default_timeout=3,\n session_state={SessionID: 1734082601, $$STREAMLIT_INTERNAL_KEY_TESTING: {}, $$STREAMLIT_INTERNAL_KEY_PAGE_SCRIPT_HASH: '60c6515387167d3d1266731a980d48b0', $$STREAMLIT_INTERNAL_KEY_SCRIPT_RUN_WITHOUT_ERRORS: False},\n _tree={\n 0: SpecialBlock(\n type='main',\n children={\n 0: Markdown(allow_html=True),\n 1: Markdown(allow_html=True),\n 2: Exception(message="SessionClient is not a BrowserWebSocketHandler! (<MagicMock name='mock.get_client()' id='4766645264'>)", stack_trace=['File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/.venv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 600, in _run_script\n exec(code, module.__dict__)', 'File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/webapps/stack_assumptions/pages/Home.py", line 25, in <module>\n Session_ID, UUID, UsersName, Session_Start, Session_State, Active_User, ActiveUsersName, Session_End, UserDict = current_session_state()', 'File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/webapps/stack_assumptions/Function_Lib/Home_funcs.py", line 32, in current_session_state\n headers = _get_websocket_headers()', 'File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/.venv/lib/python3.10/site-packages/streamlit/runtime/metrics_util.py", line 397, in wrapped_func\n result = non_optional_func(*args, **kwargs)', 'File "/Users/daniel.durkovic/PycharmProjects/dataiku-recon-general/.venv/lib/python3.10/site-packages/streamlit/web/server/websocket_headers.py", line 43, in _get_websocket_headers\n raise RuntimeError('])\n }\n ),\n 1: SpecialBlock(\n type='sidebar'\n ),\n 2: SpecialBlock(\n type='event'\n )\n }\n).exception
test_stack_assumptions.py:10: AssertionError
Streamlit, version 1.34.0
Python, version 3.10.11