Skip to content

Commit 3cd5438

Browse files
Update test_function.py
1 parent 9752198 commit 3cd5438

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tests/scenario_tests_async/test_function.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import time
44

55
import pytest
6-
from unittest.mock import AsyncMock, Mock
6+
from unittest.mock import Mock, MagicMock
77
from slack_sdk.signature import SignatureVerifier
88
from slack_sdk.web.async_client import AsyncWebClient
99

@@ -17,6 +17,8 @@
1717
)
1818
from tests.utils import remove_os_env_temporarily, restore_os_env
1919

20+
async def fake_sleep(seconds):
21+
pass
2022

2123
class TestAsyncFunction:
2224
signing_secret = "secret"
@@ -57,7 +59,7 @@ def build_request_from_body(self, message_body: dict) -> AsyncBoltRequest:
5759
timestamp, body = str(int(time.time())), json.dumps(message_body)
5860
return AsyncBoltRequest(body=body, headers=self.build_headers(timestamp, body))
5961

60-
def setup_time_mocks(self, *, monkeypatch: pytest.MonkeyPatch, time_mock: Mock, sleep_mock: AsyncMock):
62+
def setup_time_mocks(self, *, monkeypatch: pytest.MonkeyPatch, time_mock: Mock, sleep_mock: MagicMock):
6163
monkeypatch.setattr(time, "time", time_mock)
6264
monkeypatch.setattr(asyncio, "sleep", sleep_mock)
6365

@@ -142,11 +144,13 @@ async def test_auto_acknowledge_false_without_acknowledging(self, caplog, monkey
142144
)
143145
app.function("reverse", auto_acknowledge=False)(just_no_ack)
144146
request = self.build_request_from_body(function_body)
147+
145148
self.setup_time_mocks(
146149
monkeypatch=monkeypatch,
147150
time_mock=Mock(side_effect=[current_time for current_time in range(100)]),
148-
sleep_mock=AsyncMock(),
151+
sleep_mock=MagicMock(side_effect=fake_sleep),
149152
)
153+
150154
response = await app.async_dispatch(request)
151155
assert response.status == 404
152156
await assert_auth_test_count_async(self, 1)
@@ -161,7 +165,7 @@ async def test_function_handler_timeout(self, monkeypatch):
161165
app.function("reverse", auto_acknowledge=False)(just_no_ack)
162166
request = self.build_request_from_body(function_body)
163167

164-
sleep_mock = AsyncMock()
168+
sleep_mock = MagicMock(side_effect=fake_sleep)
165169
self.setup_time_mocks(
166170
monkeypatch=monkeypatch,
167171
time_mock=Mock(side_effect=[current_time for current_time in range(100)]),

0 commit comments

Comments
 (0)