diff --git a/setup.cfg b/setup.cfg index fe484f92e..2e7be5e12 100644 --- a/setup.cfg +++ b/setup.cfg @@ -122,7 +122,8 @@ exclude = [tool:pytest] markers = - slow + slow: mark a test as slow + issue: reference specific issue [mypy] ignore_missing_imports = True diff --git a/spacy/tests/conftest.py b/spacy/tests/conftest.py index a5dedcc87..10982bac1 100644 --- a/spacy/tests/conftest.py +++ b/spacy/tests/conftest.py @@ -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) diff --git a/spacy/tests/regression/test_issue8168.py b/spacy/tests/regression/test_issue8168.py index fbddf643c..e3f3b5cfa 100644 --- a/spacy/tests/regression/test_issue8168.py +++ b/spacy/tests/regression/test_issue8168.py @@ -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")