#python #python-3.x #doctest
Вопрос:
У меня есть код. a.py
from functools import cached_property, cache
import doctest
class C1:
def test_1(self):
"""
>>> C1().test_1()
'f'
"""
return "f"
@property
def test_2(self):
"""
>>> C1().test_2
'p'
"""
return "p"
@cached_property
def test_3(self):
"""
>>> C1().test_3
'cp'
"""
return "cp"
@cache
def test_4(self):
"""
>>> C1().test_4()
'c'
"""
return "c"
doctest.testmod()
test_3
это функция, украшенная @cached_property
.
У него есть докторантура. но это не было выполнено.
$ python3 a.py -v
Trying:
C1().test_1()
Expecting:
'f'
ok
Trying:
C1().test_2
Expecting:
'p'
ok
Trying:
C1().test_4()
Expecting:
'c'
ok
2 items had no tests:
__main__
__main__.C1
3 items passed all tests:
1 tests in __main__.C1.test_1
1 tests in __main__.C1.test_2
1 tests in __main__.C1.test_4
3 tests in 5 items.
3 passed and 0 failed.
Test passed.
Как я могу запустить test_3 doctest?
Окружающая среда
$ python3 --version
Python 3.9.6
$ uname
Darwin