Skip to content

Commit

Permalink
tests: Fix state contamination
Browse files Browse the repository at this point in the history
  • Loading branch information
nthykier committed Jun 1, 2024
1 parent 6f1d7c2 commit af16a68
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tests/test_class_registration.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import contextlib

import pytest
from lsprotocol.types import TEXT_DOCUMENT_COMPLETION

from pygls.protocol.language_server import PENDING_USER_LSP_METHODS
from pygls.server import LanguageServer


@contextlib.contextmanager
@pytest.fixture(autouse=True)
def reset_state() -> None:
try:
yield
finally:
# Reset after each test to ensure incorrect usage tests do no contaminate
# other tests.
PENDING_USER_LSP_METHODS.clear()


def test_instance_based_registration() -> None:

class TestLanguageServer(LanguageServer):
Expand All @@ -30,7 +44,7 @@ def do_nothing(self, param):
assert TEXT_DOCUMENT_COMPLETION in ls.lsp.fm.features


def test_class_based_registration_incorrect() -> None:
def test_class_based_registration_incorrect_before() -> None:

@LanguageServer.feature(TEXT_DOCUMENT_COMPLETION)
def do_nothing(ls, param):
Expand All @@ -42,7 +56,7 @@ class TestLanguageServer(LanguageServer):
pass


def test_class_based_registration_incorrect() -> None:
def test_class_based_registration_incorrect_after() -> None:

class TestLanguageServer(LanguageServer):
pass
Expand Down

0 comments on commit af16a68

Please sign in to comment.