Skip to content

Commit 65e3d76

Browse files
Code action test should wait for diagnostics. #66 (#223)
Co-authored-by: Eleanor Boyd <eleanorboyd@microsoft.com>
1 parent 9a1ea5b commit 65e3d76

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/test/python_tests/test_code_actions.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import os
8+
from threading import Event
89

910
import pytest
1011
from hamcrest import assert_that, is_
@@ -14,6 +15,7 @@
1415
TEST_FILE_PATH = constants.TEST_DATA / "sample1" / "sample.py"
1516
TEST_FILE_URI = utils.as_uri(str(TEST_FILE_PATH))
1617
LINTER = utils.get_server_info_defaults()["name"]
18+
TIMEOUT = 10 # 10 seconds
1719

1820

1921
@pytest.mark.parametrize(
@@ -223,11 +225,22 @@
223225
)
224226
def test_command_code_action(code, contents, command):
225227
"""Tests for code actions which run a command."""
228+
229+
actual = []
226230
with utils.python_file(contents, TEST_FILE_PATH.parent) as temp_file:
227231
uri = utils.as_uri(os.fspath(temp_file))
228232
with session.LspSession() as ls_session:
229233
ls_session.initialize()
230234

235+
done = Event()
236+
237+
def _handler(params):
238+
nonlocal actual
239+
actual = params
240+
done.set()
241+
242+
ls_session.set_notification_callback(session.PUBLISH_DIAGNOSTICS, _handler)
243+
231244
ls_session.notify_did_open(
232245
{
233246
"textDocument": {
@@ -239,6 +252,9 @@ def test_command_code_action(code, contents, command):
239252
}
240253
)
241254

255+
# wait for some time to receive all notifications
256+
done.wait(TIMEOUT)
257+
242258
diagnostics = [
243259
{
244260
"range": {

0 commit comments

Comments
 (0)