I get an issue I do not know how to solve. I see 5,000-10,000 executions of the mocked time.sleep() during my unit test. Any input on test setup or whether this is a bug?
- Running locally
- streamlit ==1.51.0, python==3.11.11
FAILED tests/test_app.py::test_app_click_ping_backend_button - AssertionError: Expected 'sleep' to have been called once. Called 7327 times.
# test_app.py
import pytest
from unittest.mock import patch
from streamlit.testing.v1 import AppTest
@pytest.fixture()
def mock_sleep():
with patch("app.path.time.sleep") as mock_time_sleep:
yield mock_time_sleep
def test_app_click_ping_backend_button(mock_component_helpers, mock_sleep):
at = AppTest.from_file("path/app.py")
at.run()
at.button[0].click()
mock_sleep.assert_called_once()
# app.py
import streamlit as st
import time
with st.sidebar:
if st.button("Rerun app"):
time.sleep(0.3)
st.rerun()