Skip to content

Commit 69cee50

Browse files
committed
chore(pdd): Disable doctest to prevent collecting twice over
1 parent 153e9e1 commit 69cee50

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

src/pytest_doctest_docutils.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,38 @@
2323

2424
import _pytest
2525
from _pytest import outcomes
26-
from _pytest.doctest import DoctestItem
2726
from _pytest.outcomes import OutcomeException
27+
from _pytest.warning_types import PytestConfigWarning
2828

2929
from doctest_docutils import DocutilsDocTestFinder, setup
3030

3131
if TYPE_CHECKING:
3232
from doctest import _Out
3333

34+
from _pytest.doctest import DoctestItem
35+
3436
logger = logging.getLogger(__name__)
3537

3638
# Lazy definition of runner class
3739
RUNNER_CLASS = None
3840

3941

42+
def pytest_configure(config: pytest.Config) -> None:
43+
"""Disable pytest.doctest to prevent running tests twice.
44+
45+
Todo: Find a way to make these plugins cooperate without collecting twice.
46+
"""
47+
if config.pluginmanager.has_plugin("doctest"):
48+
message = (
49+
"`pytest-doctest-docutils` is incompatible with `doctest`. "
50+
"Please disable `doctest` via `-p no:doctest` in order to use "
51+
"`pytest-doctest-docutils`."
52+
)
53+
54+
config.pluginmanager.set_blocked("doctest")
55+
config.issue_config_time_warning(PytestConfigWarning(message), stacklevel=3)
56+
57+
4058
def pytest_unconfigure() -> None:
4159
global RUNNER_CLASS
4260

@@ -170,7 +188,7 @@ def _DocTestRunner__patched_linecache_getlines(
170188

171189

172190
class DocTestDocutilsFile(pytest.Module):
173-
def collect(self) -> Iterable[DoctestItem]:
191+
def collect(self) -> Iterable["DoctestItem"]:
174192
setup()
175193

176194
encoding = self.config.getini("doctest_encoding")
@@ -189,6 +207,7 @@ def collect(self) -> Iterable[DoctestItem]:
189207
self.config
190208
),
191209
)
210+
from _pytest.doctest import DoctestItem
192211

193212
for test in finder.find(
194213
text,

0 commit comments

Comments
 (0)