From e69724245135f152699d3f4a8b3c20992d9448ed Mon Sep 17 00:00:00 2001 From: Keewis Date: Tue, 4 Aug 2020 20:48:59 +0200 Subject: [PATCH] fix the tests by falling back to a empty dict on AttributeError --- sphinx/ext/napoleon/docstring.py | 6 +++++- tests/test_ext_napoleon_docstring.py | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index b1e5ca3748a..ada2a790ee1 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -1131,7 +1131,11 @@ def _parse_numpydoc_see_also_section(self, content: List[str]) -> List[str]: func_name1, func_name2, :meth:`func_name`, func_name3 """ - inventory = getattr(self._app.builder.env, "intersphinx_inventory", {}) + try: + inventory = self._app.builder.env.intersphinx_inventory + except AttributeError: + inventory = {} + items = [] def parse_item_name(text: str) -> Tuple[str, str]: diff --git a/tests/test_ext_napoleon_docstring.py b/tests/test_ext_napoleon_docstring.py index 56812d19390..0894a9bff70 100644 --- a/tests/test_ext_napoleon_docstring.py +++ b/tests/test_ext_napoleon_docstring.py @@ -1365,6 +1365,7 @@ def test_see_also_refs(self): config = Config() app = mock.Mock() + app.builder.env = None actual = str(NumpyDocstring(docstring, config, app, "method")) expected = """\ @@ -1379,6 +1380,27 @@ def test_see_also_refs(self): """ self.assertEqual(expected, actual) + config = Config() + app = mock.Mock() + app.builder.env.intersphinx_inventory = { + "py:func": {"funcs": (), "otherfunc": ()}, + "py:meth": {"some": (), "other": ()}, + } + actual = str(NumpyDocstring(docstring, config, app, "method")) + + expected = """\ +numpy.multivariate_normal(mean, cov, shape=None, spam=None) + +.. seealso:: + + :meth:`some`, :meth:`other`, :func:`funcs` + \n\ + :func:`otherfunc` + relationship +""" + self.assertEqual(expected, actual) + + def test_colon_in_return_type(self): docstring = """ Summary