Merge pull request #9423 from explosion/tests/issue-marker

This commit is contained in:
Ines Montani 2021-10-13 16:53:40 +02:00 committed by GitHub
commit c48564688f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View File

@ -122,7 +122,8 @@ exclude =
[tool:pytest]
markers =
slow
slow: mark a test as slow
issue: reference specific issue
[mypy]
ignore_missing_imports = True

View File

@ -4,6 +4,7 @@ from spacy.util import get_lang_class
def pytest_addoption(parser):
parser.addoption("--slow", action="store_true", help="include slow tests")
parser.addoption("--issue", action="store", help="test specific issues")
def pytest_runtest_setup(item):
@ -16,10 +17,24 @@ def pytest_runtest_setup(item):
# options weren't given.
return item.config.getoption(f"--{opt}", False)
# Integration of boolean flags
for opt in ["slow"]:
if opt in item.keywords and not getopt(opt):
pytest.skip(f"need --{opt} option to run")
# Special integration to mark tests with issue numbers
issues = getopt("issue")
if isinstance(issues, str):
if "issue" in item.keywords:
# Convert issues provided on the CLI to list of ints
issue_nos = [int(issue.strip()) for issue in issues.split(",")]
# Get all issues specified by decorators and check if they're provided
issue_refs = [mark.args[0] for mark in item.iter_markers(name="issue")]
if not any([ref in issue_nos for ref in issue_refs]):
pytest.skip(f"not referencing specified issues: {issue_nos}")
else:
pytest.skip("not referencing any issues")
# Fixtures for language tokenizers (languages sorted alphabetically)

View File

@ -1,6 +1,8 @@
import pytest
from spacy.lang.en import English
@pytest.mark.issue(8168)
def test_issue8168():
nlp = English()
ruler = nlp.add_pipe("entity_ruler")