use clean_underscore fixture

This commit is contained in:
svlandeg 2020-02-23 15:49:20 +01:00
parent 6e717c62ed
commit b49a3afd0c
4 changed files with 11 additions and 10 deletions

View File

@ -7,6 +7,15 @@ from spacy.tokens import Doc, Span, Token
from spacy.tokens.underscore import Underscore
@pytest.fixture(scope="function", autouse=True)
def clean_underscore():
# reset the Underscore object after the test, to avoid having state copied across tests
yield
Underscore.doc_extensions = {}
Underscore.span_extensions = {}
Underscore.token_extensions = {}
def test_create_doc_underscore():
doc = Mock()
doc.doc = doc

View File

@ -6,6 +6,7 @@ import re
from mock import Mock
from spacy.matcher import Matcher, DependencyMatcher
from spacy.tokens import Doc, Token
from ..doc.test_underscore import clean_underscore
@pytest.fixture
@ -200,6 +201,7 @@ def test_matcher_any_token_operator(en_vocab):
assert matches[2] == "test hello world"
@pytest.mark.usefixtures("clean_underscore")
def test_matcher_extension_attribute(en_vocab):
matcher = Matcher(en_vocab)
get_is_fruit = lambda token: token.text in ("apple", "banana")

View File

@ -9,11 +9,6 @@ from spacy.tokens.underscore import Underscore
def test_issue4849():
nlp = English()
# reset the Underscore object because test_underscore has a lambda function that can't be pickled
Underscore.doc_extensions = {}
Underscore.span_extensions = {}
Underscore.token_extensions = {}
ruler = EntityRuler(
nlp, patterns=[
{"label": "PERSON", "pattern": 'joe biden', "id": 'joe-biden'},

View File

@ -33,11 +33,6 @@ class CustomPipe:
def test_issue4903():
# ensures that this runs correctly and doesn't hang or crash on Windows / macOS
# reset the Underscore object because test_underscore has a lambda function that can't be pickled
Underscore.doc_extensions = {}
Underscore.span_extensions = {}
Underscore.token_extensions = {}
nlp = English()
custom_component = CustomPipe()
nlp.add_pipe(nlp.create_pipe("sentencizer"))