|
5 | 5 | import warnings |
6 | 6 | import doctest |
7 | 7 |
|
8 | | -from importlib.metadata import version as get_version, PackageNotFoundError |
9 | | -from packaging.requirements import Requirement |
10 | | - |
11 | 8 | import pytest |
12 | 9 | import _pytest |
13 | 10 | from _pytest import doctest as pydoctest, outcomes |
|
16 | 13 |
|
17 | 14 | from .impl import DTParser, DebugDTRunner |
18 | 15 | from .conftest import dt_config |
19 | | -from .util import np_errstate, matplotlib_make_nongui, temp_cwd |
| 16 | +from .util import np_errstate, matplotlib_make_nongui, temp_cwd, is_req_satisfied |
20 | 17 | from .frontend import find_doctests |
21 | 18 |
|
22 | 19 |
|
@@ -93,12 +90,7 @@ def pytest_ignore_collect(collection_path, config): |
93 | 90 |
|
94 | 91 | for entry, req_str in config.dt_config.pytest_extra_requires.items(): |
95 | 92 | if fnmatch_ex(entry, collection_path): |
96 | | - # check the requirement |
97 | | - req = Requirement(req_str) |
98 | | - try: |
99 | | - return not (get_version(req.name) in req.specifier) |
100 | | - except PackageNotFoundError: |
101 | | - return True |
| 93 | + return not is_req_satisfied(req_str) |
102 | 94 |
|
103 | 95 |
|
104 | 96 | def is_private(item): |
@@ -139,6 +131,13 @@ def _maybe_add_markers(item, config): |
139 | 131 | pytest.mark.xfail(reason=reason) |
140 | 132 | ) |
141 | 133 |
|
| 134 | + extra_requires = dt_config.pytest_extra_requires |
| 135 | + if req_str := extra_requires.get(item.name, None): |
| 136 | + if not is_req_satisfied(req_str): |
| 137 | + item.add_marker( |
| 138 | + pytest.mark.skip(reason=f"requires {req_str}") |
| 139 | + ) |
| 140 | + |
142 | 141 |
|
143 | 142 | def pytest_collection_modifyitems(config, items): |
144 | 143 | """ |
|
0 commit comments