Skip to content

Commit fd5a2db

Browse files
ev-brflying-sheep
andcommitted
ENH: Allow multiple requirements per entry
Co-authored-by: Philipp A. <[email protected]>
1 parent b890535 commit fd5a2db

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

scipy_doctest/impl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class DTConfig:
9494
a string. If not empty, the string value is used as the skip reason.
9595
pytest_extra_requires : dict
9696
Paths or functions to conditionally ignore unless requirements are met.
97-
The format is ``{path/or/glob/pattern: requirement, full.func.name: requiremet}``,
97+
The format is ``{path/or/glob/pattern: requirement(s), full.func.name: requirement(s)}``,
9898
where the values are PEP 508 dependency specifiers. If a requirement is not met,
9999
the behavior is equivalent to using the ``--ignore=...`` command line switch for
100100
paths, and to using a `pytest_extra_skip` for function names.

scipy_doctest/plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ def pytest_ignore_collect(collection_path, config):
8888
if fnmatch_ex(entry, collection_path):
8989
return True
9090

91-
for entry, req_str in config.dt_config.pytest_extra_requires.items():
91+
for entry, reqs in config.dt_config.pytest_extra_requires.items():
9292
if fnmatch_ex(entry, collection_path):
93-
return not is_req_satisfied(req_str)
93+
return not is_req_satisfied(reqs)
9494

9595

9696
def is_private(item):

scipy_doctest/util.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import inspect
1111
from contextlib import contextmanager
1212

13+
from typing import Sequence
14+
1315
from importlib.metadata import version as get_version, PackageNotFoundError
1416
from packaging.requirements import Requirement
1517

@@ -257,12 +259,16 @@ def get_public_objects(module, skiplist=None):
257259
return (items, names), failures
258260

259261

260-
def is_req_satisfied(req_str):
261-
""" Check if a PEP 508-compliant requirement is satisfied or not.
262+
def is_req_satisfied(req_strs: str | Sequence[str]) -> bool:
263+
""" Check if all PEP 508-compliant requirement(s) are satisfied or not.
262264
"""
263-
req = Requirement(req_str)
265+
req_strs = [req_strs] if isinstance(req_strs, str) else req_strs
266+
reqs = [Requirement(req_str) for req_str in req_strs]
267+
if any(req.marker is not None for req in reqs):
268+
msg = r"Markers not supported in `pytest_extra_requires`"
269+
raise NotImplementedError(msg)
264270
try:
265-
return get_version(req.name) in req.specifier
271+
return all(get_version(req.name) in req.specifier for req in reqs)
266272
except PackageNotFoundError:
267273
return False
268274

0 commit comments

Comments
 (0)