2323
2424import _pytest
2525from _pytest import outcomes
26- from _pytest .doctest import DoctestItem
2726from _pytest .outcomes import OutcomeException
27+ from _pytest .warning_types import PytestConfigWarning
2828
2929from doctest_docutils import DocutilsDocTestFinder , setup
3030
3131if TYPE_CHECKING :
3232 from doctest import _Out
3333
34+ from _pytest .doctest import DoctestItem
35+
3436logger = logging .getLogger (__name__ )
3537
3638# Lazy definition of runner class
3739RUNNER_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+
4058def pytest_unconfigure () -> None :
4159 global RUNNER_CLASS
4260
@@ -170,7 +188,7 @@ def _DocTestRunner__patched_linecache_getlines(
170188
171189
172190class 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