Skip to content

Commit f7a89eb

Browse files
committed
pytest_doctest_docutils(feat): Add _unblock_doctest helper for pytest 8.1+
why: Enable programmatic re-enabling of built-in doctest plugin using the public unblock() API introduced in pytest 8.1.0. what: - Add PYTEST_VERSION constant for version-specific feature detection - Add _unblock_doctest() helper that uses pluginmanager.unblock() when available, with graceful fallback for older pytest versions
1 parent 58c6c52 commit f7a89eb

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/pytest_doctest_docutils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737

3838
logger = logging.getLogger(__name__)
3939

40+
# Parse pytest version for version-specific features
41+
PYTEST_VERSION = tuple(int(x) for x in pytest.__version__.split(".")[:2])
42+
4043
# Lazy definition of runner class
4144
RUNNER_CLASS = None
4245

@@ -68,6 +71,28 @@ def pytest_configure(config: pytest.Config) -> None:
6871
config.pluginmanager.set_blocked("doctest")
6972

7073

74+
def _unblock_doctest(config: pytest.Config) -> bool:
75+
"""Unblock doctest plugin (pytest 8.1+ only).
76+
77+
Re-enables the built-in doctest plugin after it was blocked by
78+
pytest_configure. Uses the public unblock() API introduced in pytest 8.1.0.
79+
80+
Parameters
81+
----------
82+
config : pytest.Config
83+
The pytest configuration object
84+
85+
Returns
86+
-------
87+
bool
88+
True if unblocked successfully, False if API not available
89+
"""
90+
pm = config.pluginmanager
91+
if PYTEST_VERSION >= (8, 1) and hasattr(pm, "unblock"):
92+
return pm.unblock("doctest")
93+
return False
94+
95+
7196
def pytest_unconfigure() -> None:
7297
"""Unconfigure hook for pytest-doctest-docutils."""
7398
global RUNNER_CLASS

0 commit comments

Comments
 (0)