Skip to content

Commit 625b603

Browse files
committed
Implements an option to choose the doctest output format in case of failure. (fixes #1749)
1 parent ae07985 commit 625b603

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

_pytest/doctest.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ def pytest_addoption(parser):
1717
action="store_true", default=False,
1818
help="run doctests in all .py modules",
1919
dest="doctestmodules")
20+
group.addoption("--doctest-report",
21+
type=str, default="UDIFF", choices=_get_report_choices().keys(),
22+
dest="doctestreport")
2023
group.addoption("--doctest-glob",
2124
action="append", default=[], metavar="pat",
2225
help="doctests file matching pattern, default: test*.txt",
@@ -94,7 +97,7 @@ def repr_failure(self, excinfo):
9497
message = excinfo.type.__name__
9598
reprlocation = ReprFileLocation(filename, lineno, message)
9699
checker = _get_checker()
97-
REPORT_UDIFF = doctest.REPORT_UDIFF
100+
REPORT_UDIFF = _get_report_choices().get(self.config.getoption("doctestreport"))
98101
if lineno is not None:
99102
lines = doctestfailure.test.docstring.splitlines(False)
100103
# add line numbers to the left of the error message
@@ -291,6 +294,17 @@ def _get_allow_bytes_flag():
291294
return doctest.register_optionflag('ALLOW_BYTES')
292295

293296

297+
def _get_report_choices():
298+
import doctest
299+
return dict(
300+
UDIFF=doctest.REPORT_UDIFF,
301+
CDIFF=doctest.REPORT_CDIFF,
302+
NDIFF=doctest.REPORT_NDIFF,
303+
ONLY_FIRST_FAILURE=doctest.REPORT_ONLY_FIRST_FAILURE,
304+
NONE=0,
305+
)
306+
307+
294308
@pytest.fixture(scope='session')
295309
def doctest_namespace():
296310
"""

0 commit comments

Comments
 (0)