Implements an option to choose the doctest output format in case of failure. (fixes #1749)
This commit is contained in:
parent
ae0798522f
commit
625b603f1f
|
@ -17,6 +17,9 @@ def pytest_addoption(parser):
|
||||||
action="store_true", default=False,
|
action="store_true", default=False,
|
||||||
help="run doctests in all .py modules",
|
help="run doctests in all .py modules",
|
||||||
dest="doctestmodules")
|
dest="doctestmodules")
|
||||||
|
group.addoption("--doctest-report",
|
||||||
|
type=str, default="UDIFF", choices=_get_report_choices().keys(),
|
||||||
|
dest="doctestreport")
|
||||||
group.addoption("--doctest-glob",
|
group.addoption("--doctest-glob",
|
||||||
action="append", default=[], metavar="pat",
|
action="append", default=[], metavar="pat",
|
||||||
help="doctests file matching pattern, default: test*.txt",
|
help="doctests file matching pattern, default: test*.txt",
|
||||||
|
@ -94,7 +97,7 @@ class DoctestItem(pytest.Item):
|
||||||
message = excinfo.type.__name__
|
message = excinfo.type.__name__
|
||||||
reprlocation = ReprFileLocation(filename, lineno, message)
|
reprlocation = ReprFileLocation(filename, lineno, message)
|
||||||
checker = _get_checker()
|
checker = _get_checker()
|
||||||
REPORT_UDIFF = doctest.REPORT_UDIFF
|
REPORT_UDIFF = _get_report_choices().get(self.config.getoption("doctestreport"))
|
||||||
if lineno is not None:
|
if lineno is not None:
|
||||||
lines = doctestfailure.test.docstring.splitlines(False)
|
lines = doctestfailure.test.docstring.splitlines(False)
|
||||||
# add line numbers to the left of the error message
|
# 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')
|
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')
|
@pytest.fixture(scope='session')
|
||||||
def doctest_namespace():
|
def doctest_namespace():
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue