From 625b603f1f414e59f306116ba8194673fdb0ce83 Mon Sep 17 00:00:00 2001 From: Romain Dorgueil Date: Sat, 23 Jul 2016 13:06:05 +0200 Subject: [PATCH] Implements an option to choose the doctest output format in case of failure. (fixes #1749) --- _pytest/doctest.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/_pytest/doctest.py b/_pytest/doctest.py index 649077533..3a5eb8689 100644 --- a/_pytest/doctest.py +++ b/_pytest/doctest.py @@ -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", @@ -94,7 +97,7 @@ class DoctestItem(pytest.Item): 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 @@ -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(): """