Skip to content

Commit 5cfdc6d

Browse files
Only expect ml_datasets registry entries when ml_datasets is installed
ml_datasets registers its readers through entry points and is a development requirement, not an install requirement, so running the test suite against an installed spaCy (python -m pytest --pyargs spacy) without it failed test_registry_entries. Fixes #13856
1 parent a83cdd3 commit 5cfdc6d

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎spacy/tests/test_registry_population.py‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import importlib.util
12
import json
23
from pathlib import Path
34

@@ -8,6 +9,18 @@
89
# Path to the reference registry contents, relative to this file
910
REFERENCE_FILE = Path(__file__).parent / "registry_contents.json"
1011

12+
# Registry entries that come from optional packages via entry points. They are
13+
# installed with requirements.txt for development, but not with spaCy itself,
14+
# so they are only expected when the providing package is importable.
15+
OPTIONAL_ENTRY_PREFIXES = {"ml_datasets.": "ml_datasets"}
16+
17+
18+
def _optional_entry_missing(name):
19+
for prefix, module in OPTIONAL_ENTRY_PREFIXES.items():
20+
if name.startswith(prefix):
21+
return importlib.util.find_spec(module) is None
22+
return False
23+
1124

1225
@pytest.fixture
1326
def reference_registry():
@@ -43,7 +56,9 @@ def test_registry_entries(reference_registry):
4356
current_entries = sorted(list(reg.get_all().keys()))
4457

4558
# Compare entries
46-
expected_set = set(expected_entries)
59+
expected_set = {
60+
entry for entry in expected_entries if not _optional_entry_missing(entry)
61+
}
4762
current_set = set(current_entries)
4863

4964
# Check for missing entries - these would indicate our new registry population

0 commit comments

Comments
 (0)