Skip to content

Commit 9c8fbd3

Browse files
committed
TST: Add test case for cached_property.
1 parent b138ea7 commit 9c8fbd3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

numpydoc/tests/test_docscrape.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections import namedtuple
22
from copy import deepcopy
33
import re
4+
import sys
45
import textwrap
56
import warnings
67

@@ -1624,6 +1625,26 @@ def __call__(self):
16241625
nds._error_location(msg=msg)
16251626

16261627

1628+
@pytest.mark.skipif(
1629+
sys.version_info < (3, 8), reason="cached_property was added in 3.8"
1630+
)
1631+
def test_class_docstring_cached_property():
1632+
"""Ensure that properties marked with the `cached_property` decorator
1633+
are listed in the Methods section. See gh-432."""
1634+
from functools import cached_property
1635+
1636+
class Foo:
1637+
_x = [1, 2, 3]
1638+
1639+
@cached_property
1640+
def val(self):
1641+
return self._x
1642+
1643+
class_docstring = get_doc_object(Foo)
1644+
assert len(class_docstring["Attributes"]) == 1
1645+
assert class_docstring["Attributes"][0].name == "val"
1646+
1647+
16271648
if __name__ == "__main__":
16281649
import pytest
16291650

0 commit comments

Comments
 (0)