-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pytest-lsp: Forward a server's
stderr
output
This should be enough in most cases to get pytest to report the server's log output on failure. There may be issues if there are multiple servers running concurrently/within the same session but we will cross that bridge if/when it becomes an issue.
- Loading branch information
Showing
6 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
When a test fails `pytest-lsp` will now show the server's `stderr` output (if any) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import sys | ||
|
||
from lsprotocol import types | ||
from pygls.server import LanguageServer | ||
|
||
server = LanguageServer("server-stderr", "v1") | ||
|
||
|
||
@server.feature(types.TEXT_DOCUMENT_COMPLETION) | ||
def completion(params: types.CompletionParams): | ||
items = [] | ||
|
||
for i in range(10): | ||
print(f"Suggesting item {i}", file=sys.stderr) | ||
items.append(types.CompletionItem(label=f"item-{i}")) | ||
|
||
return items | ||
|
||
|
||
if __name__ == "__main__": | ||
server.start_io() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import sys | ||
|
||
from lsprotocol.types import ClientCapabilities | ||
from lsprotocol.types import CompletionList | ||
from lsprotocol.types import CompletionParams | ||
from lsprotocol.types import InitializeParams | ||
from lsprotocol.types import Position | ||
from lsprotocol.types import TextDocumentIdentifier | ||
|
||
import pytest_lsp | ||
from pytest_lsp import ClientServerConfig | ||
from pytest_lsp import LanguageClient | ||
|
||
|
||
@pytest_lsp.fixture( | ||
config=ClientServerConfig(server_command=[sys.executable, "server.py"]), | ||
) | ||
async def client(lsp_client: LanguageClient): | ||
# Setup | ||
params = InitializeParams(capabilities=ClientCapabilities()) | ||
await lsp_client.initialize_session(params) | ||
|
||
yield | ||
|
||
# Teardown | ||
await lsp_client.shutdown_session() | ||
|
||
|
||
async def test_completions(client: LanguageClient): | ||
results = await client.text_document_completion_async( | ||
params=CompletionParams( | ||
position=Position(line=1, character=0), | ||
text_document=TextDocumentIdentifier(uri="file:///path/to/file.txt"), | ||
) | ||
) | ||
|
||
assert results is not None | ||
|
||
if isinstance(results, CompletionList): | ||
items = results.items | ||
else: | ||
items = results | ||
|
||
labels = [item.label for item in items] | ||
assert labels == [f"item-{i}" for i in range(10)] | ||
assert False # Force the test case to fail. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters