Skip to content

Commit 8c507b1

Browse files
committed
ENH: make OutputChecker pluggable in the doctest layer
1 parent 59a0649 commit 8c507b1

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

scpdt/impl.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class DTConfig:
8585
a string. If not empty, the string value is used as the skip reason.
8686
"""
8787
def __init__(self, *, # DTChecker configuration
88+
CheckerKlass=None,
8889
default_namespace=None,
8990
check_namespace=None,
9091
rndm_markers=None,
@@ -108,6 +109,8 @@ def __init__(self, *, # DTChecker configuration
108109
pytest_extra_xfail=None,
109110
):
110111
### DTChecker configuration ###
112+
self.CheckerKlass = CheckerKlass or DTChecker
113+
111114
# The namespace to run examples in
112115
self.default_namespace = default_namespace or {}
113116

@@ -340,7 +343,7 @@ def __init__(self, checker=None, verbose=None, optionflags=None, config=None):
340343
if config is None:
341344
config = DTConfig()
342345
if checker is None:
343-
checker = DTChecker(config)
346+
checker = config.CheckerKlass(config)
344347
self.nameerror_after_exception = config.nameerror_after_exception
345348
if optionflags is None:
346349
optionflags = config.optionflags

scpdt/tests/test_runner.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44

55
import pytest
66

7-
from . import failure_cases as module, finder_cases as finder_module
8-
from .. import DTFinder, DTRunner, DebugDTRunner
7+
from . import (failure_cases as module,
8+
finder_cases as finder_module,
9+
module_cases)
10+
from .. import DTFinder, DTRunner, DebugDTRunner, DTConfig
911

1012

1113
### Smoke test DTRunner methods. Mainly to check that they are runnable.
@@ -79,3 +81,25 @@ def test_debug_runner_exception(self):
7981
# exception carries the original test
8082
assert orig_exception.test is tests[0]
8183

84+
85+
class VanillaOutputChecker(doctest.OutputChecker):
86+
"""doctest.OutputChecker to drop in for DTChecker.
87+
88+
LSP break: OutputChecker does not have __init__,
89+
here we add it to agree with DTChecker.
90+
"""
91+
def __init__(self, config):
92+
pass
93+
94+
class TestCheckerDropIn:
95+
"""Test DTChecker and vanilla doctest OutputChecker being drop-in replacements.
96+
"""
97+
def test_vanilla_checker(self):
98+
config = DTConfig(CheckerKlass=VanillaOutputChecker)
99+
runner = DebugDTRunner(config=config)
100+
tests = DTFinder().find(module_cases.func)
101+
102+
with pytest.raises(doctest.DocTestFailure) as exc:
103+
for t in tests:
104+
runner.run(t)
105+

0 commit comments

Comments
 (0)