Skip to content

Commit af3d5ae

Browse files
committed
ENH: make OuputChecker pluggable in the pytest layer
1 parent 8c507b1 commit af3d5ae

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

scpdt/plugin.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ def collect(self):
213213
runner = _get_runner(self.config,
214214
verbose=False,
215215
optionflags=optionflags,
216-
checker=DTChecker(config=self.config.dt_config)
217216
)
218217

219218
# strategy='api': discover doctests in public, non-deprecated objects in module
@@ -228,7 +227,7 @@ def collect(self):
228227
yield pydoctest.DoctestItem.from_parent(
229228
self, name=test.name, runner=runner, dtest=test
230229
)
231-
230+
232231

233232
class DTTextfile(DoctestTextfile):
234233
"""
@@ -253,7 +252,6 @@ def collect(self):
253252
runner = _get_runner(self.config,
254253
verbose=False,
255254
optionflags=optionflags,
256-
checker=DTChecker(config=self.config.dt_config)
257255
)
258256

259257
# Plug in an instance of `DTParser` which parses the doctest examples from the text file and
@@ -268,7 +266,7 @@ def collect(self):
268266
)
269267

270268

271-
def _get_runner(config, checker, verbose, optionflags):
269+
def _get_runner(config, verbose, optionflags):
272270
"""
273271
Override function to return an instance of PytestDTRunner.
274272
@@ -321,5 +319,5 @@ def report_unexpected_exception(self, out, test, example, exc_info):
321319
out.append(failure)
322320
else:
323321
raise failure
324-
325-
return PytestDTRunner(checker=checker, verbose=verbose, optionflags=optionflags, config=config.dt_config)
322+
323+
return PytestDTRunner(verbose=verbose, optionflags=optionflags, config=config.dt_config)

scpdt/tests/test_pytest_configuration.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,38 @@ def test_local_file_cases(pytester):
4242
python_file = PosixPath(path_str)
4343
result = pytester.inline_run(python_file, "--doctest-modules")
4444
assert result.ret == pytest.ExitCode.OK
45+
46+
47+
def test_alt_checker(pytester):
48+
"""Test an alternative Checker."""
49+
50+
# create a temporary conftest.py file
51+
pytester.makeconftest(
52+
"""
53+
import doctest
54+
from scpdt.conftest import dt_config
55+
56+
class Vanilla(doctest.OutputChecker):
57+
def __init__(self, config):
58+
pass
59+
60+
dt_config.CheckerKlass = Vanilla
61+
"""
62+
)
63+
64+
# create a temporary pytest test file
65+
f = pytester.makepyfile(
66+
"""
67+
def func():
68+
'''
69+
>>> 2 / 3 # fails with vanilla doctest.OutputChecker
70+
0.667
71+
'''
72+
pass
73+
"""
74+
)
75+
76+
# run all tests with pytest
77+
result = pytester.inline_run(f, '--doctest-modules')
78+
assert result.ret == pytest.ExitCode.TESTS_FAILED
79+

0 commit comments

Comments
 (0)