Skip to content

Commit 9b4cca2

Browse files
committed
avoid early import of doctest
--HG-- branch : trunk
1 parent 251fb0a commit 9b4cca2

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pytest/plugin/doctest.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import py
44
from py._code.code import TerminalRepr, ReprFileLocation
5-
doctest = py.std.doctest
65

76
def pytest_addoption(parser):
87
group = parser.getgroup("collect")
@@ -39,16 +38,16 @@ def __init__(self, path, parent):
3938
self.fspath = path
4039

4140
def repr_failure(self, excinfo):
42-
if excinfo.errisinstance(doctest.DocTestFailure):
41+
if excinfo.errisinstance(py.std.doctest.DocTestFailure):
4342
doctestfailure = excinfo.value
4443
example = doctestfailure.example
4544
test = doctestfailure.test
4645
filename = test.filename
4746
lineno = test.lineno + example.lineno + 1
4847
message = excinfo.type.__name__
4948
reprlocation = ReprFileLocation(filename, lineno, message)
50-
checker = doctest.OutputChecker()
51-
REPORT_UDIFF = doctest.REPORT_UDIFF
49+
checker = py.std.doctest.OutputChecker()
50+
REPORT_UDIFF = py.std.doctest.REPORT_UDIFF
5251
filelines = py.path.local(filename).readlines(cr=0)
5352
i = max(test.lineno, max(0, lineno - 10)) # XXX?
5453
lines = []
@@ -58,7 +57,7 @@ def repr_failure(self, excinfo):
5857
lines += checker.output_difference(example,
5958
doctestfailure.got, REPORT_UDIFF).split("\n")
6059
return ReprFailDoctest(reprlocation, lines)
61-
elif excinfo.errisinstance(doctest.UnexpectedException):
60+
elif excinfo.errisinstance(py.std.doctest.UnexpectedException):
6261
excinfo = py.code.ExceptionInfo(excinfo.value.exc_info)
6362
return super(DoctestItem, self).repr_failure(excinfo)
6463
else:
@@ -70,12 +69,12 @@ def reportinfo(self):
7069
class DoctestTextfile(DoctestItem):
7170
def runtest(self):
7271
if not self._deprecated_testexecution():
73-
failed, tot = doctest.testfile(
72+
failed, tot = py.std.doctest.testfile(
7473
str(self.fspath), module_relative=False,
7574
raise_on_error=True, verbose=0)
7675

7776
class DoctestModule(DoctestItem):
7877
def runtest(self):
7978
module = self.fspath.pyimport()
80-
failed, tot = doctest.testmod(
79+
failed, tot = py.std.doctest.testmod(
8180
module, raise_on_error=True, verbose=0)

0 commit comments

Comments
 (0)