mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Avoid misreporting line number
This commit is contained in:
parent
68bccb01ac
commit
b62628f678
@ -380,6 +380,23 @@ Doctest summary
|
|||||||
return filename.encode(fs_encoding)
|
return filename.encode(fs_encoding)
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_line_number(node):
|
||||||
|
# type: (nodes.Node) -> Optional[int]
|
||||||
|
"""Get the real line number or admit we don't know."""
|
||||||
|
# TODO: Work out how to store or calculate real (file-relative)
|
||||||
|
# line numbers for doctest blocks in docstrings.
|
||||||
|
if ':docstring of ' in path.basename(node.source or ''):
|
||||||
|
# The line number is given relative to the stripped docstring,
|
||||||
|
# not the file. This is correct where it is set, in
|
||||||
|
# `docutils.nodes.Node.setup_child`, but Sphinx should report
|
||||||
|
# relative to the file, not the docstring.
|
||||||
|
return None
|
||||||
|
if node.line is not None:
|
||||||
|
# TODO: find the root cause of this off by one error.
|
||||||
|
return node.line - 1
|
||||||
|
return None
|
||||||
|
|
||||||
def test_doc(self, docname, doctree):
|
def test_doc(self, docname, doctree):
|
||||||
# type: (unicode, nodes.Node) -> None
|
# type: (unicode, nodes.Node) -> None
|
||||||
groups = {} # type: Dict[unicode, TestGroup]
|
groups = {} # type: Dict[unicode, TestGroup]
|
||||||
@ -408,12 +425,13 @@ Doctest summary
|
|||||||
for node in doctree.traverse(condition):
|
for node in doctree.traverse(condition):
|
||||||
source = node['test'] if 'test' in node else node.astext()
|
source = node['test'] if 'test' in node else node.astext()
|
||||||
filename = self.get_filename_for_node(node, docname)
|
filename = self.get_filename_for_node(node, docname)
|
||||||
|
line_number = self.get_line_number(node)
|
||||||
if not source:
|
if not source:
|
||||||
logger.warning('no code/output in %s block at %s:%s',
|
logger.warning('no code/output in %s block at %s:%s',
|
||||||
node.get('testnodetype', 'doctest'),
|
node.get('testnodetype', 'doctest'),
|
||||||
filename, node.line)
|
filename, line_number)
|
||||||
code = TestCode(source, type=node.get('testnodetype', 'doctest'),
|
code = TestCode(source, type=node.get('testnodetype', 'doctest'),
|
||||||
filename=filename, lineno=node.line,
|
filename=filename, lineno=line_number,
|
||||||
options=node.get('options'))
|
options=node.get('options'))
|
||||||
node_groups = node.get('groups', ['default'])
|
node_groups = node.get('groups', ['default'])
|
||||||
if '*' in node_groups:
|
if '*' in node_groups:
|
||||||
|
@ -71,8 +71,8 @@ def test_reporting_with_autodoc(app, status, warning, capfd):
|
|||||||
failures = [l for l in lines if l.startswith('File')]
|
failures = [l for l in lines if l.startswith('File')]
|
||||||
expected = [
|
expected = [
|
||||||
'File "dir/inner.rst", line 1, in default',
|
'File "dir/inner.rst", line 1, in default',
|
||||||
'File "dir/bar.py", line 2, in default',
|
'File "dir/bar.py", line ?, in default',
|
||||||
'File "foo.py", line 3, in default',
|
'File "foo.py", line ?, in default',
|
||||||
'File "index.rst", line 4, in default',
|
'File "index.rst", line 4, in default',
|
||||||
]
|
]
|
||||||
for location in expected:
|
for location in expected:
|
||||||
|
Loading…
Reference in New Issue
Block a user