5
5
import os
6
6
import shutil
7
7
import warnings
8
+ import doctest
8
9
9
- from _pytest import doctest , outcomes
10
+ from _pytest import doctest as pydoctest , outcomes
10
11
from _pytest .doctest import DoctestModule , DoctestTextfile
11
12
from _pytest .pathlib import import_path
12
- from _pytest .outcomes import skip , OutcomeException
13
13
14
14
from scpdt .impl import DTChecker , DTParser , DebugDTRunner
15
15
from scpdt .conftest import dt_config
16
- from .util import np_errstate , matplotlib_make_nongui
16
+ from scpdt .util import np_errstate , matplotlib_make_nongui
17
17
from scpdt .frontend import find_doctests
18
18
19
19
@@ -29,8 +29,8 @@ def pytest_configure(config):
29
29
config .dt_config = dt_config
30
30
31
31
# Override doctest's objects with the plugin's alternative implementation.
32
- doctest .DoctestModule = DTModule
33
- doctest .DoctestTextfile = DTTextfile
32
+ pydoctest .DoctestModule = DTModule
33
+ pydoctest .DoctestTextfile = DTTextfile
34
34
35
35
36
36
def pytest_unconfigure (config ):
@@ -160,7 +160,7 @@ def collect(self):
160
160
)
161
161
except ImportError :
162
162
if self .config .getvalue ("doctest_ignore_import_errors" ):
163
- skip ("unable to import module %r" % self .path )
163
+ outcomes . skip ("unable to import module %r" % self .path )
164
164
else :
165
165
raise
166
166
@@ -182,7 +182,7 @@ def collect(self):
182
182
# NB: additional postprocessing in pytest_collection_modifyitems
183
183
for test in find_doctests (module , strategy = "api" , name = module .__name__ , config = dt_config ):
184
184
if test .examples : # skip empty doctests
185
- yield doctest .DoctestItem .from_parent (
185
+ yield pydoctest .DoctestItem .from_parent (
186
186
self , name = test .name , runner = runner , dtest = test
187
187
)
188
188
except :
@@ -206,7 +206,7 @@ def collect(self):
206
206
name = self .path .name
207
207
globs = {"__name__" : "__main__" }
208
208
209
- optionflags = doctest .get_optionflags (self )
209
+ optionflags = pydoctest .get_optionflags (self )
210
210
211
211
# Copy local files specified by the `local_resources` attribute to the current working directory
212
212
if self .config .dt_config .local_resources :
@@ -226,7 +226,7 @@ def collect(self):
226
226
# This part of the code is unchanged
227
227
test = parser .get_doctest (text , globs , name , filename , 0 )
228
228
if test .examples :
229
- yield doctest .DoctestItem .from_parent (
229
+ yield pydoctest .DoctestItem .from_parent (
230
230
self , name = test .name , runner = runner , dtest = test
231
231
)
232
232
@@ -238,8 +238,6 @@ def _get_runner(config, checker, verbose, optionflags):
238
238
This function creates and returns an instance of PytestDTRunner, a custom runner class
239
239
that extends the behavior of DebugDTRunner for running doctests in pytest.
240
240
"""
241
- import doctest
242
-
243
241
class PytestDTRunner (DebugDTRunner ):
244
242
def run (self , test , compileflags = None , out = None , clear_globs = False ):
245
243
"""
@@ -273,7 +271,7 @@ def report_failure(self, out, test, example, got):
273
271
raise failure
274
272
275
273
def report_unexpected_exception (self , out , test , example , exc_info ):
276
- if isinstance (exc_info [1 ], OutcomeException ):
274
+ if isinstance (exc_info [1 ], outcomes . OutcomeException ):
277
275
raise exc_info [1 ]
278
276
if isinstance (exc_info [1 ], bdb .BdbQuit ):
279
277
outcomes .exit ("Quitting debugger" )
0 commit comments