Skip to content

Commit a79e646

Browse files
authored
Merge pull request #125 from ev-br/main_pydoctest
MAINT: clean up imports, naming in the plugin
2 parents 1582d03 + 800a54d commit a79e646

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

scpdt/plugin.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import os
66
import shutil
77
import warnings
8+
import doctest
89

9-
from _pytest import doctest, outcomes
10+
from _pytest import doctest as pydoctest, outcomes
1011
from _pytest.doctest import DoctestModule, DoctestTextfile
1112
from _pytest.pathlib import import_path
12-
from _pytest.outcomes import skip, OutcomeException
1313

1414
from scpdt.impl import DTChecker, DTParser, DebugDTRunner
1515
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
1717
from scpdt.frontend import find_doctests
1818

1919

@@ -29,8 +29,8 @@ def pytest_configure(config):
2929
config.dt_config = dt_config
3030

3131
# 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
3434

3535

3636
def pytest_unconfigure(config):
@@ -160,7 +160,7 @@ def collect(self):
160160
)
161161
except ImportError:
162162
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)
164164
else:
165165
raise
166166

@@ -182,7 +182,7 @@ def collect(self):
182182
# NB: additional postprocessing in pytest_collection_modifyitems
183183
for test in find_doctests(module, strategy="api", name=module.__name__, config=dt_config):
184184
if test.examples: # skip empty doctests
185-
yield doctest.DoctestItem.from_parent(
185+
yield pydoctest.DoctestItem.from_parent(
186186
self, name=test.name, runner=runner, dtest=test
187187
)
188188
except:
@@ -206,7 +206,7 @@ def collect(self):
206206
name = self.path.name
207207
globs = {"__name__": "__main__"}
208208

209-
optionflags = doctest.get_optionflags(self)
209+
optionflags = pydoctest.get_optionflags(self)
210210

211211
# Copy local files specified by the `local_resources` attribute to the current working directory
212212
if self.config.dt_config.local_resources:
@@ -226,7 +226,7 @@ def collect(self):
226226
# This part of the code is unchanged
227227
test = parser.get_doctest(text, globs, name, filename, 0)
228228
if test.examples:
229-
yield doctest.DoctestItem.from_parent(
229+
yield pydoctest.DoctestItem.from_parent(
230230
self, name=test.name, runner=runner, dtest=test
231231
)
232232

@@ -238,8 +238,6 @@ def _get_runner(config, checker, verbose, optionflags):
238238
This function creates and returns an instance of PytestDTRunner, a custom runner class
239239
that extends the behavior of DebugDTRunner for running doctests in pytest.
240240
"""
241-
import doctest
242-
243241
class PytestDTRunner(DebugDTRunner):
244242
def run(self, test, compileflags=None, out=None, clear_globs=False):
245243
"""
@@ -273,7 +271,7 @@ def report_failure(self, out, test, example, got):
273271
raise failure
274272

275273
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):
277275
raise exc_info[1]
278276
if isinstance(exc_info[1], bdb.BdbQuit):
279277
outcomes.exit("Quitting debugger")

0 commit comments

Comments
 (0)