Skip to content

Commit

Permalink
Implements an option to choose the doctest output format in case of f…
Browse files Browse the repository at this point in the history
…ailure. (fixes #1749)
  • Loading branch information
hartym committed Jul 23, 2016
1 parent ae07985 commit 625b603
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion _pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def pytest_addoption(parser):
action="store_true", default=False,
help="run doctests in all .py modules",
dest="doctestmodules")
group.addoption("--doctest-report",
type=str, default="UDIFF", choices=_get_report_choices().keys(),
dest="doctestreport")
group.addoption("--doctest-glob",
action="append", default=[], metavar="pat",
help="doctests file matching pattern, default: test*.txt",
Expand Down Expand Up @@ -94,7 +97,7 @@ def repr_failure(self, excinfo):
message = excinfo.type.__name__
reprlocation = ReprFileLocation(filename, lineno, message)
checker = _get_checker()
REPORT_UDIFF = doctest.REPORT_UDIFF
REPORT_UDIFF = _get_report_choices().get(self.config.getoption("doctestreport"))
if lineno is not None:
lines = doctestfailure.test.docstring.splitlines(False)
# add line numbers to the left of the error message
Expand Down Expand Up @@ -291,6 +294,17 @@ def _get_allow_bytes_flag():
return doctest.register_optionflag('ALLOW_BYTES')


def _get_report_choices():
import doctest
return dict(
UDIFF=doctest.REPORT_UDIFF,
CDIFF=doctest.REPORT_CDIFF,
NDIFF=doctest.REPORT_NDIFF,
ONLY_FIRST_FAILURE=doctest.REPORT_ONLY_FIRST_FAILURE,
NONE=0,
)


@pytest.fixture(scope='session')
def doctest_namespace():
"""
Expand Down

0 comments on commit 625b603

Please sign in to comment.